| @@ -150,12 +150,12 @@ using namespace juce; | |||||
| namespace juce | namespace juce | ||||
| { | { | ||||
| #include "native/juce_MidiDataConcatenator.h" | |||||
| //============================================================================== | //============================================================================== | ||||
| #if JUCE_MAC | #if JUCE_MAC | ||||
| #include "../juce_core/native/juce_osx_ObjCHelpers.h" | #include "../juce_core/native/juce_osx_ObjCHelpers.h" | ||||
| #include "../juce_core/native/juce_mac_ObjCSuffix.h" | #include "../juce_core/native/juce_mac_ObjCSuffix.h" | ||||
| #include "native/juce_MidiDataConcatenator.h" | |||||
| #include "native/juce_mac_CoreAudio.cpp" | #include "native/juce_mac_CoreAudio.cpp" | ||||
| #include "native/juce_mac_CoreMidi.cpp" | #include "native/juce_mac_CoreMidi.cpp" | ||||
| @@ -170,12 +170,10 @@ namespace juce | |||||
| //============================================================================== | //============================================================================== | ||||
| #elif JUCE_IOS | #elif JUCE_IOS | ||||
| #include "native/juce_ios_Audio.cpp" | #include "native/juce_ios_Audio.cpp" | ||||
| #include "native/juce_MidiDataConcatenator.h" | |||||
| #include "native/juce_mac_CoreMidi.cpp" | #include "native/juce_mac_CoreMidi.cpp" | ||||
| //============================================================================== | //============================================================================== | ||||
| #elif JUCE_WINDOWS | #elif JUCE_WINDOWS | ||||
| #include "native/juce_MidiDataConcatenator.h" | |||||
| #include "../juce_core/native/juce_win32_ComSmartPtr.h" | #include "../juce_core/native/juce_win32_ComSmartPtr.h" | ||||
| #include "../juce_events/native/juce_win32_HiddenMessageWindow.h" | #include "../juce_events/native/juce_win32_HiddenMessageWindow.h" | ||||
| @@ -44,13 +44,13 @@ URL::URL (const String& url_) | |||||
| { | { | ||||
| if (nextAmp < 0) | if (nextAmp < 0) | ||||
| { | { | ||||
| parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)), | |||||
| removeEscapeChars (url.substring (equalsPos + 1))); | |||||
| addParameter (removeEscapeChars (url.substring (i + 1, equalsPos)), | |||||
| removeEscapeChars (url.substring (equalsPos + 1))); | |||||
| } | } | ||||
| else if (nextAmp > 0 && equalsPos < nextAmp) | else if (nextAmp > 0 && equalsPos < nextAmp) | ||||
| { | { | ||||
| parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)), | |||||
| removeEscapeChars (url.substring (equalsPos + 1, nextAmp))); | |||||
| addParameter (removeEscapeChars (url.substring (i + 1, equalsPos)), | |||||
| removeEscapeChars (url.substring (equalsPos + 1, nextAmp))); | |||||
| } | } | ||||
| } | } | ||||
| @@ -65,7 +65,8 @@ URL::URL (const String& url_) | |||||
| URL::URL (const URL& other) | URL::URL (const URL& other) | ||||
| : url (other.url), | : url (other.url), | ||||
| postData (other.postData), | postData (other.postData), | ||||
| parameters (other.parameters), | |||||
| parameterNames (other.parameterNames), | |||||
| parameterValues (other.parameterValues), | |||||
| filesToUpload (other.filesToUpload), | filesToUpload (other.filesToUpload), | ||||
| mimeTypes (other.mimeTypes) | mimeTypes (other.mimeTypes) | ||||
| { | { | ||||
| @@ -75,7 +76,8 @@ URL& URL::operator= (const URL& other) | |||||
| { | { | ||||
| url = other.url; | url = other.url; | ||||
| postData = other.postData; | postData = other.postData; | ||||
| parameters = other.parameters; | |||||
| parameterNames = other.parameterNames; | |||||
| parameterValues = other.parameterValues; | |||||
| filesToUpload = other.filesToUpload; | filesToUpload = other.filesToUpload; | ||||
| mimeTypes = other.mimeTypes; | mimeTypes = other.mimeTypes; | ||||
| @@ -86,7 +88,8 @@ bool URL::operator== (const URL& other) const | |||||
| { | { | ||||
| return url == other.url | return url == other.url | ||||
| && postData == other.postData | && postData == other.postData | ||||
| && parameters == other.parameters | |||||
| && parameterNames == other.parameterNames | |||||
| && parameterValues == other.parameterValues | |||||
| && filesToUpload == other.filesToUpload | && filesToUpload == other.filesToUpload | ||||
| && mimeTypes == other.mimeTypes; | && mimeTypes == other.mimeTypes; | ||||
| } | } | ||||
| @@ -102,18 +105,19 @@ URL::~URL() | |||||
| namespace URLHelpers | namespace URLHelpers | ||||
| { | { | ||||
| String getMangledParameters (const StringPairArray& parameters) | |||||
| String getMangledParameters (const URL& url) | |||||
| { | { | ||||
| jassert (url.getParameterNames().size() == url.getParameterValues().size()); | |||||
| String p; | String p; | ||||
| for (int i = 0; i < parameters.size(); ++i) | |||||
| for (int i = 0; i < url.getParameterNames().size(); ++i) | |||||
| { | { | ||||
| if (i > 0) | if (i > 0) | ||||
| p << '&'; | p << '&'; | ||||
| p << URL::addEscapeChars (parameters.getAllKeys() [i], true) | |||||
| p << URL::addEscapeChars (url.getParameterNames()[i], true) | |||||
| << '=' | << '=' | ||||
| << URL::addEscapeChars (parameters.getAllValues() [i], true); | |||||
| << URL::addEscapeChars (url.getParameterValues()[i], true); | |||||
| } | } | ||||
| return p; | return p; | ||||
| @@ -158,12 +162,12 @@ namespace URLHelpers | |||||
| data << "--" << boundary; | data << "--" << boundary; | ||||
| int i; | int i; | ||||
| for (i = 0; i < url.getParameters().size(); ++i) | |||||
| for (i = 0; i < url.getParameterNames().size(); ++i) | |||||
| { | { | ||||
| data << "\r\nContent-Disposition: form-data; name=\"" | data << "\r\nContent-Disposition: form-data; name=\"" | ||||
| << url.getParameters().getAllKeys() [i] | |||||
| << url.getParameterNames() [i] | |||||
| << "\"\r\n\r\n" | << "\"\r\n\r\n" | ||||
| << url.getParameters().getAllValues() [i] | |||||
| << url.getParameterValues() [i] | |||||
| << "\r\n--" | << "\r\n--" | ||||
| << boundary; | << boundary; | ||||
| } | } | ||||
| @@ -190,7 +194,8 @@ namespace URLHelpers | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| data << getMangledParameters (url.getParameters()) << url.getPostData(); | |||||
| data << getMangledParameters (url) | |||||
| << url.getPostData(); | |||||
| // just a short text attachment, so use simple url encoding.. | // just a short text attachment, so use simple url encoding.. | ||||
| headers << "Content-Type: application/x-www-form-urlencoded\r\nContent-length: " | headers << "Content-Type: application/x-www-form-urlencoded\r\nContent-length: " | ||||
| @@ -210,10 +215,16 @@ namespace URLHelpers | |||||
| } | } | ||||
| } | } | ||||
| void URL::addParameter (const String& name, const String& value) | |||||
| { | |||||
| parameterNames.add (name); | |||||
| parameterValues.add (value); | |||||
| } | |||||
| String URL::toString (const bool includeGetParameters) const | String URL::toString (const bool includeGetParameters) const | ||||
| { | { | ||||
| if (includeGetParameters && parameters.size() > 0) | |||||
| return url + "?" + URLHelpers::getMangledParameters (parameters); | |||||
| if (includeGetParameters && parameterNames.size() > 0) | |||||
| return url + "?" + URLHelpers::getMangledParameters (*this); | |||||
| else | else | ||||
| return url; | return url; | ||||
| } | } | ||||
| @@ -363,7 +374,7 @@ URL URL::withParameter (const String& parameterName, | |||||
| const String& parameterValue) const | const String& parameterValue) const | ||||
| { | { | ||||
| URL u (*this); | URL u (*this); | ||||
| u.parameters.set (parameterName, parameterValue); | |||||
| u.addParameter (parameterName, parameterValue); | |||||
| return u; | return u; | ||||
| } | } | ||||
| @@ -386,11 +397,6 @@ URL URL::withPOSTData (const String& postData_) const | |||||
| return u; | return u; | ||||
| } | } | ||||
| const StringPairArray& URL::getParameters() const | |||||
| { | |||||
| return parameters; | |||||
| } | |||||
| const StringPairArray& URL::getFilesToUpload() const | const StringPairArray& URL::getFilesToUpload() const | ||||
| { | { | ||||
| return filesToUpload; | return filesToUpload; | ||||
| @@ -129,6 +129,8 @@ public: | |||||
| e.g. calling "withParameter ("amount", "some fish") for the url "www.fish.com" | e.g. calling "withParameter ("amount", "some fish") for the url "www.fish.com" | ||||
| would produce a new url whose toString(true) method would return | would produce a new url whose toString(true) method would return | ||||
| "www.fish.com?amount=some+fish". | "www.fish.com?amount=some+fish". | ||||
| @see getParameterNames, getParameterValues | |||||
| */ | */ | ||||
| URL withParameter (const String& parameterName, | URL withParameter (const String& parameterName, | ||||
| const String& parameterValue) const; | const String& parameterValue) const; | ||||
| @@ -145,16 +147,31 @@ public: | |||||
| const File& fileToUpload, | const File& fileToUpload, | ||||
| const String& mimeType) const; | const String& mimeType) const; | ||||
| /** Returns a set of all the parameters encoded into the url. | |||||
| /** Returns an array of the names of all the URL's parameters. | |||||
| E.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would | |||||
| contain two items: "type" and "haddock". | |||||
| You can call getParameterValues() to get the corresponding value of each | |||||
| parameter. Note that the list can contain multiple parameters with the same name. | |||||
| @see getParameterValues, withParameter | |||||
| */ | |||||
| const StringArray& getParameterNames() const noexcept { return parameterNames; } | |||||
| /** Returns an array of the values of all the URL's parameters. | |||||
| E.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would | E.g. for the url "www.fish.com?type=haddock&amount=some+fish", this array would | ||||
| contain two pairs: "type" => "haddock" and "amount" => "some fish". | |||||
| contain two items: "haddock" and "some fish". | |||||
| The values returned will have been cleaned up to remove any escape characters. | The values returned will have been cleaned up to remove any escape characters. | ||||
| @see getNamedParameter, withParameter | |||||
| You can call getParameterNames() to get the corresponding name of each | |||||
| parameter. Note that the list can contain multiple parameters with the same name. | |||||
| @see getParameterNames, withParameter | |||||
| */ | */ | ||||
| const StringPairArray& getParameters() const; | |||||
| const StringArray& getParameterValues() const noexcept { return parameterValues; } | |||||
| /** Returns the set of files that should be uploaded as part of a POST operation. | /** Returns the set of files that should be uploaded as part of a POST operation. | ||||
| @@ -181,9 +198,8 @@ public: | |||||
| */ | */ | ||||
| URL withPOSTData (const String& postData) const; | URL withPOSTData (const String& postData) const; | ||||
| /** Returns the data that was set using withPOSTData(). | |||||
| */ | |||||
| String getPostData() const { return postData; } | |||||
| /** Returns the data that was set using withPOSTData(). */ | |||||
| const String& getPostData() const noexcept { return postData; } | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Tries to launch the system's default browser to open the URL. | /** Tries to launch the system's default browser to open the URL. | ||||
| @@ -315,7 +331,10 @@ public: | |||||
| private: | private: | ||||
| //============================================================================== | //============================================================================== | ||||
| String url, postData; | String url, postData; | ||||
| StringPairArray parameters, filesToUpload, mimeTypes; | |||||
| StringArray parameterNames, parameterValues; | |||||
| StringPairArray filesToUpload, mimeTypes; | |||||
| void addParameter (const String&, const String&); | |||||
| static InputStream* createNativeStream (const String& address, bool isPost, const MemoryBlock& postData, | static InputStream* createNativeStream (const String& address, bool isPost, const MemoryBlock& postData, | ||||
| OpenStreamProgressCallback* progressCallback, | OpenStreamProgressCallback* progressCallback, | ||||