diff options
Diffstat (limited to 'dep/CascLib/src/common/FileStream.cpp')
-rw-r--r-- | dep/CascLib/src/common/FileStream.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/dep/CascLib/src/common/FileStream.cpp b/dep/CascLib/src/common/FileStream.cpp index 622af421a82..7151ca9f36d 100644 --- a/dep/CascLib/src/common/FileStream.cpp +++ b/dep/CascLib/src/common/FileStream.cpp @@ -672,20 +672,22 @@ static DWORD BaseHttp_ParseURL(TFileStream * pStream, LPCTSTR szFileName, int * static bool BaseHttp_Download(TFileStream * pStream) { + CASC_MIME_RESPONSE MimeResponse; + CASC_BLOB FileData; CASC_MIME Mime; const char * request_mask = "GET %s HTTP/1.1\r\nHost: %s\r\nConnection: Keep-Alive\r\n\r\n"; char * server_response; char * fileName = pStream->Base.Socket.fileName; char request[0x100]; - size_t response_length = 0; size_t request_length = 0; - DWORD dwErrCode; + DWORD dwErrCode = ERROR_SUCCESS; // If we already have the data, it's success if(pStream->Base.Socket.fileData == NULL) { // Reset the file data length as well pStream->Base.Socket.fileDataLength = 0; + dwErrCode = ERROR_BAD_FORMAT; // Construct the request, either HTTP or Ribbit (https://wowdev.wiki/Ribbit). // Note that Ribbit requests don't start with slash @@ -698,31 +700,31 @@ static bool BaseHttp_Download(TFileStream * pStream) // Send the request and receive decoded response request_length = CascStrPrintf(request, _countof(request), request_mask, fileName, pStream->Base.Socket.hostName); - server_response = pStream->Base.Socket.pSocket->ReadResponse(request, request_length, &response_length); + server_response = pStream->Base.Socket.pSocket->ReadResponse(request, request_length, MimeResponse); if(server_response != NULL) { - // Check for non-zero data - if(response_length != 0) + // Decode the MIME document + if((dwErrCode = Mime.Load(server_response, MimeResponse)) == ERROR_SUCCESS) { - // Decode the MIME document - if((dwErrCode = Mime.Load(server_response, response_length)) == ERROR_SUCCESS) + // Move the data from MIME to HTTP stream + if((dwErrCode = Mime.GiveAway(FileData)) == ERROR_SUCCESS) { - // Move the data from MIME to HTTP stream - pStream->Base.Socket.fileData = Mime.GiveAway(&pStream->Base.Socket.fileDataLength); + pStream->Base.Socket.fileData = FileData.pbData; + pStream->Base.Socket.fileDataLength = FileData.cbData; + pStream->Base.Socket.fileDataPos = 0; + FileData.Reset(); } } - else - { - SetCascError(ERROR_BAD_FORMAT); - } // Free the buffer CASC_FREE(server_response); } } - // If we have data loaded, return true - return (pStream->Base.Socket.fileData != NULL); + // Process error codes + if(dwErrCode != ERROR_SUCCESS) + SetCascError(dwErrCode); + return (dwErrCode == ERROR_SUCCESS); } static bool BaseHttp_Open(TFileStream * pStream, LPCTSTR szFileName, DWORD dwStreamFlags) |