diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 6fa481c13c..a799d610c0 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -246441,120 +246441,133 @@ private: if (sessionHandle != 0) { // break up the url.. - TCHAR file[1024], server[1024], username[1024], password[1024]; + const int fileNumChars = 65536; + const int serverNumChars = 2048; + const int usernameNumChars = 1024; + const int passwordNumChars = 1024; + HeapBlock file (fileNumChars), server (serverNumChars), + username (usernameNumChars), password (passwordNumChars); URL_COMPONENTS uc = { 0 }; uc.dwStructSize = sizeof (uc); uc.lpszUrlPath = file; - uc.dwUrlPathLength = numElementsInArray (file); + uc.dwUrlPathLength = fileNumChars; uc.lpszHostName = server; - uc.dwHostNameLength = numElementsInArray (server); + uc.dwHostNameLength = serverNumChars; uc.lpszUserName = username; - uc.dwUserNameLength = numElementsInArray (username); + uc.dwUserNameLength = usernameNumChars; uc.lpszPassword = password; - uc.dwPasswordLength = numElementsInArray (password); + uc.dwPasswordLength = passwordNumChars; if (InternetCrackUrl (address.toWideCharPointer(), 0, 0, &uc)) - { - int disable = 1; - InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable)); + openConnection (uc, sessionHandle, progressCallback, progressCallbackContext); + } + } - if (timeOutMs == 0) - timeOutMs = 30000; - else if (timeOutMs < 0) - timeOutMs = -1; + void openConnection (URL_COMPONENTS& uc, HINTERNET sessionHandle, + URL::OpenStreamProgressCallback* progressCallback, + void* progressCallbackContext) + { + int disable = 1; + InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable)); - InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs)); + if (timeOutMs == 0) + timeOutMs = 30000; + else if (timeOutMs < 0) + timeOutMs = -1; - const bool isFtp = address.startsWithIgnoreCase ("ftp:"); + InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs)); - #if WORKAROUND_TIMEOUT_BUG - connection = 0; + const bool isFtp = address.startsWithIgnoreCase ("ftp:"); - { - InternetConnectThread connectThread (uc, sessionHandle, connection, isFtp); - connectThread.wait (timeOutMs); + #if WORKAROUND_TIMEOUT_BUG + connection = 0; - if (connection == 0) - { - InternetCloseHandle (sessionHandle); - sessionHandle = 0; - } - } - #else - connection = InternetConnect (sessionHandle, uc.lpszHostName, uc.nPort, - uc.lpszUserName, uc.lpszPassword, - isFtp ? INTERNET_SERVICE_FTP - : INTERNET_SERVICE_HTTP, - 0, 0); - #endif - - if (connection != 0) - { - if (isFtp) - { - request = FtpOpenFile (connection, uc.lpszUrlPath, GENERIC_READ, - FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE, 0); - } - else - { - const TCHAR* mimeTypes[] = { _T("*/*"), 0 }; + { + InternetConnectThread connectThread (uc, sessionHandle, connection, isFtp); + connectThread.wait (timeOutMs); - DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES; + if (connection == 0) + { + InternetCloseHandle (sessionHandle); + sessionHandle = 0; + } + } + #else + connection = InternetConnect (sessionHandle, uc.lpszHostName, uc.nPort, + uc.lpszUserName, uc.lpszPassword, + isFtp ? INTERNET_SERVICE_FTP + : INTERNET_SERVICE_HTTP, + 0, 0); + #endif - if (address.startsWithIgnoreCase ("https:")) - flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 - - // IE7 seems to automatically work out when it's https) + if (connection != 0) + { + if (isFtp) + request = FtpOpenFile (connection, uc.lpszUrlPath, GENERIC_READ, + FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE, 0); + else + openHTTPConnection (uc, sessionHandle, progressCallback, progressCallbackContext); + } + } - request = HttpOpenRequest (connection, isPost ? _T("POST") : _T("GET"), - uc.lpszUrlPath, 0, 0, mimeTypes, flags, 0); + void openHTTPConnection (URL_COMPONENTS& uc, HINTERNET sessionHandle, + URL::OpenStreamProgressCallback* progressCallback, + void* progressCallbackContext) + { + const TCHAR* mimeTypes[] = { _T("*/*"), 0 }; - if (request != 0) - { - INTERNET_BUFFERS buffers = { 0 }; - buffers.dwStructSize = sizeof (INTERNET_BUFFERS); - buffers.lpcszHeader = headers.toWideCharPointer(); - buffers.dwHeadersLength = headers.length(); - buffers.dwBufferTotal = (DWORD) postData.getSize(); + DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES; - if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0)) - { - int bytesSent = 0; + if (address.startsWithIgnoreCase ("https:")) + flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 - + // IE7 seems to automatically work out when it's https) - for (;;) - { - const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent); - DWORD bytesDone = 0; + request = HttpOpenRequest (connection, isPost ? _T("POST") : _T("GET"), + uc.lpszUrlPath, 0, 0, mimeTypes, flags, 0); - if (bytesToDo > 0 - && ! InternetWriteFile (request, - static_cast (postData.getData()) + bytesSent, - bytesToDo, &bytesDone)) - { - break; - } + if (request != 0) + { + INTERNET_BUFFERS buffers = { 0 }; + buffers.dwStructSize = sizeof (INTERNET_BUFFERS); + buffers.lpcszHeader = headers.toWideCharPointer(); + buffers.dwHeadersLength = headers.length(); + buffers.dwBufferTotal = (DWORD) postData.getSize(); - if (bytesToDo == 0 || (int) bytesDone < bytesToDo) - { - if (HttpEndRequest (request, 0, 0, 0)) - return; + if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0)) + { + int bytesSent = 0; - break; - } + for (;;) + { + const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent); + DWORD bytesDone = 0; - bytesSent += bytesDone; + if (bytesToDo > 0 + && ! InternetWriteFile (request, + static_cast (postData.getData()) + bytesSent, + bytesToDo, &bytesDone)) + { + break; + } - if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, bytesSent, postData.getSize())) - break; - } - } - } + if (bytesToDo == 0 || (int) bytesDone < bytesToDo) + { + if (HttpEndRequest (request, 0, 0, 0)) + return; - close(); + break; } + + bytesSent += bytesDone; + + if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, bytesSent, postData.getSize())) + break; } } } + + close(); } JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebInputStream); @@ -262114,20 +262127,18 @@ bool File::setAsCurrentWorkingDirectory() const namespace { - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - typedef struct stat64 juce_statStruct; // (need to use the 64-bit version to work around a simulator bug) - #else - typedef struct stat juce_statStruct; - #endif + #if JUCE_LINUX || (JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T) // (this iOS stuff is to avoid a simulator bug) + typedef struct stat64 juce_statStruct; + #define JUCE_STAT stat64 + #else + typedef struct stat juce_statStruct; + #define JUCE_STAT stat + #endif bool juce_stat (const String& fileName, juce_statStruct& info) { return fileName.isNotEmpty() - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - && (stat64 (fileName.toUTF8(), &info) == 0); - #else - && (stat (fileName.toUTF8(), &info) == 0); - #endif + && JUCE_STAT (fileName.toUTF8(), &info) == 0; } // if this file doesn't exist, find a parent of it that does.. @@ -262147,14 +262158,14 @@ namespace void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize, Time* const modTime, Time* const creationTime, bool* const isReadOnly) { - if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0) + if (isDir != nullptr || fileSize != nullptr || modTime != nullptr || creationTime != nullptr) { juce_statStruct info; const bool statOk = juce_stat (path, info); - if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); - if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0; - if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0); + if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); + if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0; + if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0); if (creationTime != nullptr) *creationTime = Time (statOk ? (int64) info.st_ctime * 1000 : 0); } @@ -262183,14 +262194,8 @@ bool File::isDirectory() const bool File::exists() const { - juce_statStruct info; - return fullPath.isNotEmpty() - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - && (lstat64 (fullPath.toUTF8(), &info) == 0); - #else - && (lstat (fullPath.toUTF8(), &info) == 0); - #endif + && access (fullPath.toUTF8(), F_OK) == 0; } bool File::existsAsFile() const @@ -272056,20 +272061,18 @@ bool File::setAsCurrentWorkingDirectory() const namespace { - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - typedef struct stat64 juce_statStruct; // (need to use the 64-bit version to work around a simulator bug) - #else - typedef struct stat juce_statStruct; - #endif + #if JUCE_LINUX || (JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T) // (this iOS stuff is to avoid a simulator bug) + typedef struct stat64 juce_statStruct; + #define JUCE_STAT stat64 + #else + typedef struct stat juce_statStruct; + #define JUCE_STAT stat + #endif bool juce_stat (const String& fileName, juce_statStruct& info) { return fileName.isNotEmpty() - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - && (stat64 (fileName.toUTF8(), &info) == 0); - #else - && (stat (fileName.toUTF8(), &info) == 0); - #endif + && JUCE_STAT (fileName.toUTF8(), &info) == 0; } // if this file doesn't exist, find a parent of it that does.. @@ -272089,14 +272092,14 @@ namespace void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize, Time* const modTime, Time* const creationTime, bool* const isReadOnly) { - if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0) + if (isDir != nullptr || fileSize != nullptr || modTime != nullptr || creationTime != nullptr) { juce_statStruct info; const bool statOk = juce_stat (path, info); - if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); - if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0; - if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0); + if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); + if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0; + if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0); if (creationTime != nullptr) *creationTime = Time (statOk ? (int64) info.st_ctime * 1000 : 0); } @@ -272125,14 +272128,8 @@ bool File::isDirectory() const bool File::exists() const { - juce_statStruct info; - return fullPath.isNotEmpty() - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - && (lstat64 (fullPath.toUTF8(), &info) == 0); - #else - && (lstat (fullPath.toUTF8(), &info) == 0); - #endif + && access (fullPath.toUTF8(), F_OK) == 0; } bool File::existsAsFile() const @@ -289063,20 +289060,18 @@ bool File::setAsCurrentWorkingDirectory() const namespace { - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - typedef struct stat64 juce_statStruct; // (need to use the 64-bit version to work around a simulator bug) - #else - typedef struct stat juce_statStruct; - #endif + #if JUCE_LINUX || (JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T) // (this iOS stuff is to avoid a simulator bug) + typedef struct stat64 juce_statStruct; + #define JUCE_STAT stat64 + #else + typedef struct stat juce_statStruct; + #define JUCE_STAT stat + #endif bool juce_stat (const String& fileName, juce_statStruct& info) { return fileName.isNotEmpty() - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - && (stat64 (fileName.toUTF8(), &info) == 0); - #else - && (stat (fileName.toUTF8(), &info) == 0); - #endif + && JUCE_STAT (fileName.toUTF8(), &info) == 0; } // if this file doesn't exist, find a parent of it that does.. @@ -289096,14 +289091,14 @@ namespace void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize, Time* const modTime, Time* const creationTime, bool* const isReadOnly) { - if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0) + if (isDir != nullptr || fileSize != nullptr || modTime != nullptr || creationTime != nullptr) { juce_statStruct info; const bool statOk = juce_stat (path, info); - if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); - if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0; - if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0); + if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); + if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0; + if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0); if (creationTime != nullptr) *creationTime = Time (statOk ? (int64) info.st_ctime * 1000 : 0); } @@ -289132,14 +289127,8 @@ bool File::isDirectory() const bool File::exists() const { - juce_statStruct info; - return fullPath.isNotEmpty() - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - && (lstat64 (fullPath.toUTF8(), &info) == 0); - #else - && (lstat (fullPath.toUTF8(), &info) == 0); - #endif + && access (fullPath.toUTF8(), F_OK) == 0; } bool File::existsAsFile() const diff --git a/juce_amalgamated.h b/juce_amalgamated.h index d8411c25c1..86a022d88b 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -73,7 +73,7 @@ namespace JuceDummyNamespace {} */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 54 -#define JUCE_BUILDNUMBER 11 +#define JUCE_BUILDNUMBER 12 /** Current Juce version number. diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index 097877e457..a480580eb9 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -33,7 +33,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 54 -#define JUCE_BUILDNUMBER 11 +#define JUCE_BUILDNUMBER 12 /** Current Juce version number. diff --git a/src/native/common/juce_posix_SharedCode.h b/src/native/common/juce_posix_SharedCode.h index 91e18ecd3f..ec8eac7346 100644 --- a/src/native/common/juce_posix_SharedCode.h +++ b/src/native/common/juce_posix_SharedCode.h @@ -225,20 +225,18 @@ bool File::setAsCurrentWorkingDirectory() const //============================================================================== namespace { - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - typedef struct stat64 juce_statStruct; // (need to use the 64-bit version to work around a simulator bug) - #else - typedef struct stat juce_statStruct; - #endif + #if JUCE_LINUX || (JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T) // (this iOS stuff is to avoid a simulator bug) + typedef struct stat64 juce_statStruct; + #define JUCE_STAT stat64 + #else + typedef struct stat juce_statStruct; + #define JUCE_STAT stat + #endif bool juce_stat (const String& fileName, juce_statStruct& info) { return fileName.isNotEmpty() - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - && (stat64 (fileName.toUTF8(), &info) == 0); - #else - && (stat (fileName.toUTF8(), &info) == 0); - #endif + && JUCE_STAT (fileName.toUTF8(), &info) == 0; } // if this file doesn't exist, find a parent of it that does.. @@ -258,14 +256,14 @@ namespace void updateStatInfoForFile (const String& path, bool* const isDir, int64* const fileSize, Time* const modTime, Time* const creationTime, bool* const isReadOnly) { - if (isDir != 0 || fileSize != 0 || modTime != 0 || creationTime != 0) + if (isDir != nullptr || fileSize != nullptr || modTime != nullptr || creationTime != nullptr) { juce_statStruct info; const bool statOk = juce_stat (path, info); - if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); - if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0; - if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0); + if (isDir != nullptr) *isDir = statOk && ((info.st_mode & S_IFDIR) != 0); + if (fileSize != nullptr) *fileSize = statOk ? info.st_size : 0; + if (modTime != nullptr) *modTime = Time (statOk ? (int64) info.st_mtime * 1000 : 0); if (creationTime != nullptr) *creationTime = Time (statOk ? (int64) info.st_ctime * 1000 : 0); } @@ -294,14 +292,8 @@ bool File::isDirectory() const bool File::exists() const { - juce_statStruct info; - return fullPath.isNotEmpty() - #if JUCE_IOS && ! __DARWIN_ONLY_64_BIT_INO_T - && (lstat64 (fullPath.toUTF8(), &info) == 0); - #else - && (lstat (fullPath.toUTF8(), &info) == 0); - #endif + && access (fullPath.toUTF8(), F_OK) == 0; } bool File::existsAsFile() const diff --git a/src/native/windows/juce_win32_Network.cpp b/src/native/windows/juce_win32_Network.cpp index dc48cb0523..67f891860c 100644 --- a/src/native/windows/juce_win32_Network.cpp +++ b/src/native/windows/juce_win32_Network.cpp @@ -225,120 +225,133 @@ private: if (sessionHandle != 0) { // break up the url.. - TCHAR file[1024], server[1024], username[1024], password[1024]; + const int fileNumChars = 65536; + const int serverNumChars = 2048; + const int usernameNumChars = 1024; + const int passwordNumChars = 1024; + HeapBlock file (fileNumChars), server (serverNumChars), + username (usernameNumChars), password (passwordNumChars); URL_COMPONENTS uc = { 0 }; uc.dwStructSize = sizeof (uc); uc.lpszUrlPath = file; - uc.dwUrlPathLength = numElementsInArray (file); + uc.dwUrlPathLength = fileNumChars; uc.lpszHostName = server; - uc.dwHostNameLength = numElementsInArray (server); + uc.dwHostNameLength = serverNumChars; uc.lpszUserName = username; - uc.dwUserNameLength = numElementsInArray (username); + uc.dwUserNameLength = usernameNumChars; uc.lpszPassword = password; - uc.dwPasswordLength = numElementsInArray (password); + uc.dwPasswordLength = passwordNumChars; if (InternetCrackUrl (address.toWideCharPointer(), 0, 0, &uc)) + openConnection (uc, sessionHandle, progressCallback, progressCallbackContext); + } + } + + void openConnection (URL_COMPONENTS& uc, HINTERNET sessionHandle, + URL::OpenStreamProgressCallback* progressCallback, + void* progressCallbackContext) + { + int disable = 1; + InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable)); + + if (timeOutMs == 0) + timeOutMs = 30000; + else if (timeOutMs < 0) + timeOutMs = -1; + + InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs)); + + const bool isFtp = address.startsWithIgnoreCase ("ftp:"); + + #if WORKAROUND_TIMEOUT_BUG + connection = 0; + + { + InternetConnectThread connectThread (uc, sessionHandle, connection, isFtp); + connectThread.wait (timeOutMs); + + if (connection == 0) { - int disable = 1; - InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable)); + InternetCloseHandle (sessionHandle); + sessionHandle = 0; + } + } + #else + connection = InternetConnect (sessionHandle, uc.lpszHostName, uc.nPort, + uc.lpszUserName, uc.lpszPassword, + isFtp ? INTERNET_SERVICE_FTP + : INTERNET_SERVICE_HTTP, + 0, 0); + #endif - if (timeOutMs == 0) - timeOutMs = 30000; - else if (timeOutMs < 0) - timeOutMs = -1; + if (connection != 0) + { + if (isFtp) + request = FtpOpenFile (connection, uc.lpszUrlPath, GENERIC_READ, + FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE, 0); + else + openHTTPConnection (uc, sessionHandle, progressCallback, progressCallbackContext); + } + } - InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs)); + void openHTTPConnection (URL_COMPONENTS& uc, HINTERNET sessionHandle, + URL::OpenStreamProgressCallback* progressCallback, + void* progressCallbackContext) + { + const TCHAR* mimeTypes[] = { _T("*/*"), 0 }; - const bool isFtp = address.startsWithIgnoreCase ("ftp:"); + DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES; - #if WORKAROUND_TIMEOUT_BUG - connection = 0; + if (address.startsWithIgnoreCase ("https:")) + flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 - + // IE7 seems to automatically work out when it's https) - { - InternetConnectThread connectThread (uc, sessionHandle, connection, isFtp); - connectThread.wait (timeOutMs); + request = HttpOpenRequest (connection, isPost ? _T("POST") : _T("GET"), + uc.lpszUrlPath, 0, 0, mimeTypes, flags, 0); - if (connection == 0) - { - InternetCloseHandle (sessionHandle); - sessionHandle = 0; - } - } - #else - connection = InternetConnect (sessionHandle, uc.lpszHostName, uc.nPort, - uc.lpszUserName, uc.lpszPassword, - isFtp ? INTERNET_SERVICE_FTP - : INTERNET_SERVICE_HTTP, - 0, 0); - #endif - - if (connection != 0) + if (request != 0) + { + INTERNET_BUFFERS buffers = { 0 }; + buffers.dwStructSize = sizeof (INTERNET_BUFFERS); + buffers.lpcszHeader = headers.toWideCharPointer(); + buffers.dwHeadersLength = headers.length(); + buffers.dwBufferTotal = (DWORD) postData.getSize(); + + if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0)) + { + int bytesSent = 0; + + for (;;) { - if (isFtp) + const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent); + DWORD bytesDone = 0; + + if (bytesToDo > 0 + && ! InternetWriteFile (request, + static_cast (postData.getData()) + bytesSent, + bytesToDo, &bytesDone)) { - request = FtpOpenFile (connection, uc.lpszUrlPath, GENERIC_READ, - FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE, 0); + break; } - else + + if (bytesToDo == 0 || (int) bytesDone < bytesToDo) { - const TCHAR* mimeTypes[] = { _T("*/*"), 0 }; - - DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES; - - if (address.startsWithIgnoreCase ("https:")) - flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 - - // IE7 seems to automatically work out when it's https) - - request = HttpOpenRequest (connection, isPost ? _T("POST") : _T("GET"), - uc.lpszUrlPath, 0, 0, mimeTypes, flags, 0); - - if (request != 0) - { - INTERNET_BUFFERS buffers = { 0 }; - buffers.dwStructSize = sizeof (INTERNET_BUFFERS); - buffers.lpcszHeader = headers.toWideCharPointer(); - buffers.dwHeadersLength = headers.length(); - buffers.dwBufferTotal = (DWORD) postData.getSize(); - - if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0)) - { - int bytesSent = 0; - - for (;;) - { - const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent); - DWORD bytesDone = 0; - - if (bytesToDo > 0 - && ! InternetWriteFile (request, - static_cast (postData.getData()) + bytesSent, - bytesToDo, &bytesDone)) - { - break; - } - - if (bytesToDo == 0 || (int) bytesDone < bytesToDo) - { - if (HttpEndRequest (request, 0, 0, 0)) - return; - - break; - } - - bytesSent += bytesDone; - - if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, bytesSent, postData.getSize())) - break; - } - } - } - - close(); + if (HttpEndRequest (request, 0, 0, 0)) + return; + + break; } + + bytesSent += bytesDone; + + if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, bytesSent, postData.getSize())) + break; } } } + + close(); } JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (WebInputStream);