/*---------------------------------------------------------------------- | NPT_LogManager::ParseConfig +---------------------------------------------------------------------*/ NPT_Result NPT_LogManager::ParseConfig(const char* config, NPT_Size config_size) { const char* cursor = config; const char* line = config; const char* separator = NULL; NPT_String key; NPT_String value; /* parse all entries */ while (cursor <= config+config_size) { /* separators are newlines, ';' or end of buffer */ if ( cursor == config+config_size || *cursor == '\n' || *cursor == '\r' || *cursor == ';') { /* newline or end of buffer */ if (separator && line[0] != '#') { /* we have a property */ key.Assign(line, (NPT_Size)(separator-line)); value.Assign(line+(separator+1-line), (NPT_Size)(cursor-(separator+1))); key.Trim(" \t"); value.Trim(" \t"); SetConfigValue((const char*)key, (const char*)value); } line = cursor+1; separator = NULL; } else if (*cursor == '=' && separator == NULL) { separator = cursor; } cursor++; } return NPT_SUCCESS; }
void FrontEnd::httpConnectorOnNewClient(HttpServerTask *task, Interface *intf, NPT_Socket *client) { NPT_Result nr; NPT_InputStreamReference inputStream0; nr = client->GetInputStream(inputStream0); if (NPT_FAILED(nr)) { return; } NPT_OutputStreamReference outputStream; nr = client->GetOutputStream(outputStream); if (NPT_FAILED(nr)) { return; } NPT_BufferedInputStreamReference inputStream(new NPT_BufferedInputStream(inputStream0)); NPT_HttpRequest *req; nr = NPT_HttpRequest::Parse(*inputStream.AsPointer(), NULL, req); if (NPT_FAILED(nr)) { return; } // TODO: validate "HOST" ??? RequestContext reqCtx; reqCtx.clientHint = CH_Unknown; reqCtx.transferMode = TM_None; reqCtx.getcontentFeaturesReq = false; NPT_HttpHeader *hdrUserAgent = req->GetHeaders().GetHeader(NPT_HTTP_HEADER_USER_AGENT); if (hdrUserAgent) { if (hdrUserAgent->GetValue().Find("xbox", 0, true) >= 0) { NPT_LOG_INFO_1("XBox found [User-Agent: %s]", hdrUserAgent->GetValue().GetChars()); reqCtx.clientHint = CH_XBox; } } NPT_HttpHeader *hdrTransferMode = req->GetHeaders().GetHeader("transferMode.dlna.org"); if (hdrTransferMode) { const NPT_String& transferMode = hdrTransferMode->GetValue(); if (transferMode.Compare("Streaming", true) == 0) { reqCtx.transferMode = TM_Streaming; } else if (transferMode.Compare("Interactive", true) == 0) { reqCtx.transferMode = TM_Interactive; } else if (transferMode.Compare("Background", true) == 0) { reqCtx.transferMode = TM_Background; } else { reqCtx.transferMode = TM_Unknown; } } NPT_HttpHeader *hdrGetContentFeatures = req->GetHeaders().GetHeader("getcontentFeatures.dlna.org"); if (hdrGetContentFeatures) { NPT_String getContentFeatures = hdrGetContentFeatures->GetValue(); if (getContentFeatures.Trim().Compare("1") == 0) { reqCtx.getcontentFeaturesReq = true; } } NPT_SocketInfo si; client->GetInfo(si); onHttpRequestHeader(si, req); PtrHolder<NPT_HttpRequest> req1(req); NPT_String reqPath(req->GetUrl().GetPath()); NPT_TimeStamp ts; NPT_System::GetCurrentTimeStamp(ts); NPT_String dateStr = NPT_DateTime(ts).ToString(NPT_DateTime::FORMAT_RFC_1123); NPT_HttpResponse *resp = new NPT_HttpResponse(200, "OK", NPT_HTTP_PROTOCOL_1_1); PtrHolder<NPT_HttpResponse> resp1(resp); resp->GetHeaders().SetHeader(NPT_HTTP_HEADER_SERVER, m_serverHeader); resp->GetHeaders().SetHeader("Date", dateStr); resp->GetHeaders().SetHeader(NPT_HTTP_HEADER_CONTENT_LENGTH, "0"); resp->GetHeaders().SetHeader(NPT_HTTP_HEADER_CONTENT_TYPE, "text/xml"); HttpOutput *httpOutput = new HttpOutputImpl(this, si, outputStream); PtrHolder<HttpOutput> httpOutput1(httpOutput); { ReadLocker locker(m_cpLock); for (NPT_Ordinal i = 0; i < m_controlPointList.GetItemCount(); i++) { NPT_List<ControlPointInfo*>::Iterator it = m_controlPointList.GetItem(i); ControlPointInfo *info = *it; if (reqPath.StartsWith(info->m_context.m_httpRoot)) { NPT_InputStream *input = inputStream.AsPointer(); inputStream.Detach(); httpOutput1.detach(); resp1.detach(); req1.detach(); task->detach(); return info->m_controlPoint->processHttpRequest(&intf->m_context, reqPath.SubString(info->m_context.m_httpRoot.GetLength()), reqCtx, req, resp, input, httpOutput, client); } } } { 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; if (reqPath.StartsWith(info->m_context.m_httpRoot)) { NPT_InputStream *input = inputStream.AsPointer(); inputStream.Detach(); httpOutput1.detach(); resp1.detach(); req1.detach(); task->detach(); return info->m_deviceImpl->processHttpRequest(&intf->m_context, reqPath.SubString(info->m_context.m_httpRoot.GetLength()), reqCtx, req, resp, input, httpOutput, client); } } } setStatusCode(*resp, 404); httpOutput->writeResponseHeader(*resp); httpOutput->flush(); }