From 3d5b7685cd932f6dff0e0bf9abe9d542b44be6db Mon Sep 17 00:00:00 2001 From: Julian Storer Date: Fri, 9 Sep 2011 08:46:39 +0100 Subject: [PATCH] Tweaked linux HTTP code. Added a macro: JUCE_STRINGIFY. --- .../juce_core/native/juce_linux_Network.cpp | 29 ++++++++++++------- modules/juce_core/system/juce_PlatformDefs.h | 12 ++++++-- modules/juce_core/system/juce_SystemStats.cpp | 13 ++------- 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/modules/juce_core/native/juce_linux_Network.cpp b/modules/juce_core/native/juce_linux_Network.cpp index 1e94ac43e5..f6b2ea2b17 100644 --- a/modules/juce_core/native/juce_linux_Network.cpp +++ b/modules/juce_core/native/juce_linux_Network.cpp @@ -338,25 +338,34 @@ private: dest << "\r\n" << key << ' ' << value; } + static void writeHost (MemoryOutputStream& dest, const bool isPost, const String& path, const String& host, const int port) + { + dest << (isPost ? "POST " : "GET ") << path << " HTTP/1.1\r\nHost: " << host; + + if (port > 0) + dest << ':' << port; + } + static MemoryBlock createRequestHeader (const String& hostName, const int hostPort, const String& proxyName, const int proxyPort, const String& hostPath, const String& originalURL, - const String& headers, const MemoryBlock& postData, + const String& userHeaders, const MemoryBlock& postData, const bool isPost) { MemoryOutputStream header; - header << (isPost ? "POST " : "GET "); - if (proxyName.isEmpty()) - header << hostPath << " HTTP/1.0\r\nHost: " << hostName << ':' << hostPort; + writeHost (header, isPost, hostPath, hostName, hostPort); else - header << originalURL << " HTTP/1.0\r\nHost: " << proxyName << ':' << proxyPort; + writeHost (header, isPost, originalURL, proxyName, proxyPort); + + writeValueIfNotPresent (header, userHeaders, "User-Agent:", "JUCE/" JUCE_STRINGIFY(JUCE_MAJOR_VERSION) + "." JUCE_STRINGIFY(JUCE_MINOR_VERSION) + "." JUCE_STRINGIFY(JUCE_BUILDNUMBER)); + writeValueIfNotPresent (header, userHeaders, "Connection:", "Close"); + writeValueIfNotPresent (header, userHeaders, "Content-Length:", String ((int) postData.getSize())); - writeValueIfNotPresent (header, headers, "User-Agent:", "JUCE/" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION)); - writeValueIfNotPresent (header, headers, "Connection:", "Close"); - writeValueIfNotPresent (header, headers, "Content-Length:", String ((int) postData.getSize())); - header << "\r\n" << headers + header << "\r\n" << userHeaders << "\r\n" << postData; return header.getMemoryBlock(); @@ -407,7 +416,7 @@ private: } else { - port = 80; + port = 0; // indicates the default port if (nextSlash >= 0) host = url.substring (7, nextSlash); diff --git a/modules/juce_core/system/juce_PlatformDefs.h b/modules/juce_core/system/juce_PlatformDefs.h index 06b0394864..9240dde894 100644 --- a/modules/juce_core/system/juce_PlatformDefs.h +++ b/modules/juce_core/system/juce_PlatformDefs.h @@ -182,14 +182,20 @@ //============================================================================== #if ! DOXYGEN - #define JUCE_JOIN_MACRO_HELPER(a, b) a ## b + #define JUCE_JOIN_MACRO_HELPER(a, b) a ## b + #define JUCE_STRINGIFY_MACRO_HELPER(a) #a #endif /** A good old-fashioned C macro concatenation helper. This combines two items (which may themselves be macros) into a single string, avoiding the pitfalls of the ## macro operator. */ -#define JUCE_JOIN_MACRO(a, b) JUCE_JOIN_MACRO_HELPER (a, b) +#define JUCE_JOIN_MACRO(item1, item2) JUCE_JOIN_MACRO_HELPER (item1, item2) + +/** A handy C macro for stringifying any symbol, rather than just a macro parameter. +*/ +#define JUCE_STRINGIFY(item) JUCE_STRINGIFY_MACRO_HELPER (item) + //============================================================================== #if JUCE_CATCH_UNHANDLED_EXCEPTIONS @@ -212,7 +218,7 @@ } \ catch (...) \ { \ - JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__); \ + JUCEApplication::sendUnhandledException (nullptr, __FILE__, __LINE__); \ } #endif diff --git a/modules/juce_core/system/juce_SystemStats.cpp b/modules/juce_core/system/juce_SystemStats.cpp index 81d7e5931a..d9cabe9e99 100644 --- a/modules/juce_core/system/juce_SystemStats.cpp +++ b/modules/juce_core/system/juce_SystemStats.cpp @@ -46,16 +46,9 @@ String SystemStats::getJUCEVersion() static_jassert (sizeof (int64) == 8); static_jassert (sizeof (uint64) == 8); - // (these confusing macros convert numbers into a single string literal) - #define JUCE_STRINGIFYVERSION2(a) #a - #define JUCE_STRINGIFYVERSION(a) JUCE_STRINGIFYVERSION2(a) - - return "JUCE v" JUCE_STRINGIFYVERSION(JUCE_MAJOR_VERSION) - "." JUCE_STRINGIFYVERSION(JUCE_MINOR_VERSION) - "." JUCE_STRINGIFYVERSION(JUCE_BUILDNUMBER); - - #undef JUCE_STRINGIFYVERSION - #undef JUCE_STRINGIFYVERSION2 + return "JUCE v" JUCE_STRINGIFY(JUCE_MAJOR_VERSION) + "." JUCE_STRINGIFY(JUCE_MINOR_VERSION) + "." JUCE_STRINGIFY(JUCE_BUILDNUMBER); } #if JUCE_DEBUG && ! JUCE_ANDROID