XBOX::VError VHTTPResponse::_SendResponseHeader() { if (fHeaderSent) return XBOX::VE_OK; // Not sure we have to report the error _NormalizeResponseHeader(); // Write Status-Line XBOX::VString string; XBOX::VString fieldValue; HTTPProtocol::MakeStatusLine (fHTTPVersion, fResponseStatusCode, string); /* Write Server Header */ if (GetHeaders().IsHeaderSet (STRING_HEADER_SERVER)) GetHeaders().RemoveHeader (STRING_HEADER_SERVER); HTTPProtocol::MakeServerString (fieldValue, false, true); string.AppendString (fieldValue); string.AppendCString (HTTP_CRLF); /* Write Date Header */ if (!GetHeaders().IsHeaderSet (STRING_HEADER_DATE)) { HTTPProtocol::MakeRFC822GMTDateString (GMT_NOW, fieldValue, true); string.AppendString (fieldValue); string.AppendCString (HTTP_CRLF); } // Write Headers GetHeaders().ToString (string); string.AppendCString (HTTP_CRLF); XBOX::StStringConverter<char> converter (string, XBOX::VTC_UTF_8); char * buffer = (char *)converter.GetCPointer(); uLONG bufferSize = (uLONG)converter.GetSize(); XBOX::VError error = _WriteToSocket (buffer, &bufferSize); fHeaderSent = (XBOX::VE_OK == error); return error; }
XBOX::VError VHTTPServerLog::_Flush() { XBOX::VFilePath logFilePath; XBOX::VError error = XBOX::VE_OK; _GetLogFilePath (logFilePath); if (!logFilePath.IsValid()) return XBOX::VE_FILE_NOT_FOUND; if (fLogFileAccessLock.Lock()) { if (NULL == fLogFile) fLogFile = new XBOX::VFile (logFilePath); if (testAssert (NULL != fLogFile)) { XBOX::VFileDesc *fileDesc = NULL; error = fLogFile->Open (XBOX::FA_READ_WRITE, &fileDesc, XBOX::FO_CreateIfNotFound); if ((XBOX::VE_OK == error) && (NULL != fileDesc)) { sLONG8 logFileSize = fileDesc->GetSize(); if ((CHAR_NUMBER_SIGN != fRequestsBuffer.GetUniChar (1)) && (0 == logFileSize)) { XBOX::VString fileHeader; _WriteFileHeader (fileHeader); XBOX::StStringConverter<char> buffer (fileHeader, XBOX::VTC_DefaultTextExport); fileDesc->SetPos (fileDesc->GetSize()); error = fileDesc->PutDataAtPos (buffer.GetCPointer(), buffer.GetSize()); fileDesc->Flush(); } if (fLogBufferAccessLock.Lock()) { // Flushing the buffer XBOX::StStringConverter<char> buffer (fRequestsBuffer, XBOX::VTC_DefaultTextExport); fileDesc->SetPos (fileDesc->GetSize()); error = fileDesc->PutDataAtPos (buffer.GetCPointer(), buffer.GetSize()); fRequestsBuffer.Clear(); fRequestsInBuffer = 0; fLogBufferAccessLock.Unlock(); } error = fileDesc->Flush(); fLogFileSize = fileDesc->GetSize(); delete fileDesc; fileDesc = NULL; } else { error = VE_CANNOT_OPEN_LOG_FILE; } } else { error = VE_CANNOT_CREATE_LOG_FILE; } fLogFileAccessLock.Unlock(); _CalculateNextFileRotationTime(); } return error; }