From d2e2935f9d59a9b9f032efec9d6fe75b57d0ad8f Mon Sep 17 00:00:00 2001 From: Chunting Gu Date: Wed, 5 Sep 2018 15:59:21 +0800 Subject: [PATCH] Move soap specific definitions to separate files --- webcc/CMakeLists.txt | 2 ++ webcc/globals.cc | 30 ++++++++---------------------- webcc/globals.h | 14 +++----------- webcc/soap_async_client.cc | 1 + webcc/soap_client.cc | 1 + webcc/soap_globals.cc | 13 +++++++++++++ webcc/soap_globals.h | 17 +++++++++++++++++ webcc/soap_request_handler.cc | 2 +- 8 files changed, 46 insertions(+), 34 deletions(-) create mode 100644 webcc/soap_globals.cc create mode 100644 webcc/soap_globals.h diff --git a/webcc/CMakeLists.txt b/webcc/CMakeLists.txt index a3e28b0..b1734ae 100644 --- a/webcc/CMakeLists.txt +++ b/webcc/CMakeLists.txt @@ -70,6 +70,7 @@ if(WEBCC_ENABLE_SOAP) set(SOAP_HEADERS soap_async_client.h soap_client.h + soap_globals.h soap_message.h soap_parameter.h soap_response.h @@ -83,6 +84,7 @@ if(WEBCC_ENABLE_SOAP) set(SOAP_SOURCES soap_async_client.cc soap_client.cc + soap_globals.cc soap_message.cc soap_response.cc soap_request.cc diff --git a/webcc/globals.cc b/webcc/globals.cc index 7e4980b..83120df 100644 --- a/webcc/globals.cc +++ b/webcc/globals.cc @@ -1,7 +1,5 @@ #include "webcc/globals.h" -#include // for move() - namespace webcc { // ----------------------------------------------------------------------------- @@ -12,28 +10,16 @@ const std::string kHost = "Host"; const std::string kContentType = "Content-Type"; const std::string kContentLength = "Content-Length"; -#ifdef WEBCC_ENABLE_SOAP -const std::string kSoapAction = "SOAPAction"; -#endif // WEBCC_ENABLE_SOAP - const std::string kAppJsonUtf8 = "application/json; charset=utf-8"; -#ifdef WEBCC_ENABLE_SOAP -// According to www.w3.org when placing SOAP messages in HTTP bodies, the HTTP -// Content-type header must be chosen as "application/soap+xml" [RFC 3902]. -// But in practice, many web servers cannot understand it. -// See: https://www.w3.org/TR/2007/REC-soap12-part0-20070427/#L26854 -const std::string kTextXmlUtf8 = "text/xml; charset=utf-8"; -#endif // WEBCC_ENABLE_SOAP - -const std::string kHttpPort = "80"; -const std::string kHttpsPort = "443"; - -const std::string kHttpHead = "HEAD"; -const std::string kHttpGet = "GET"; -const std::string kHttpPost = "POST"; -const std::string kHttpPatch = "PATCH"; -const std::string kHttpPut = "PUT"; +const std::string kHttpPort = "80"; +const std::string kHttpSslPort = "443"; + +const std::string kHttpHead = "HEAD"; +const std::string kHttpGet = "GET"; +const std::string kHttpPost = "POST"; +const std::string kHttpPatch = "PATCH"; +const std::string kHttpPut = "PUT"; const std::string kHttpDelete = "DELETE"; // ----------------------------------------------------------------------------- diff --git a/webcc/globals.h b/webcc/globals.h index 3e908f9..03976b9 100644 --- a/webcc/globals.h +++ b/webcc/globals.h @@ -7,7 +7,7 @@ // Macros // Does the compiler support "= default" for move copy constructor and -// assignment operator? +// move assignment operator? #ifdef _MSC_VER #if _MSC_VER <= 1800 // VS 2013 #define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 0 @@ -33,7 +33,7 @@ const char* const CRLF = "\r\n"; // Default buffer size for socket reading. const std::size_t kBufferSize = 1024; -const std::size_t kInvalidLength = static_cast(-1); +const std::size_t kInvalidLength = std::string::npos; // Default timeout for reading response. const int kMaxReadSeconds = 30; @@ -42,19 +42,11 @@ extern const std::string kHost; extern const std::string kContentType; extern const std::string kContentLength; -#ifdef WEBCC_ENABLE_SOAP -extern const std::string kSoapAction; -#endif // WEBCC_ENABLE_SOAP - extern const std::string kAppJsonUtf8; -#ifdef WEBCC_ENABLE_SOAP -extern const std::string kTextXmlUtf8; -#endif // WEBCC_ENABLE_SOAP - // Default ports. extern const std::string kHttpPort; -extern const std::string kHttpsPort; +extern const std::string kHttpSslPort; // HTTP methods (verbs) in string ("HEAD", "GET", etc.). // NOTE: Don't use enum to avoid converting back and forth. diff --git a/webcc/soap_async_client.cc b/webcc/soap_async_client.cc index 0545b02..70321a2 100644 --- a/webcc/soap_async_client.cc +++ b/webcc/soap_async_client.cc @@ -4,6 +4,7 @@ #include // for move() #include "webcc/http_async_client.h" +#include "webcc/soap_globals.h" #include "webcc/soap_request.h" #include "webcc/soap_response.h" diff --git a/webcc/soap_client.cc b/webcc/soap_client.cc index 5dfd283..4bc50a2 100644 --- a/webcc/soap_client.cc +++ b/webcc/soap_client.cc @@ -4,6 +4,7 @@ #include // for move() #include "webcc/http_client.h" +#include "webcc/soap_globals.h" #include "webcc/soap_request.h" #include "webcc/soap_response.h" diff --git a/webcc/soap_globals.cc b/webcc/soap_globals.cc new file mode 100644 index 0000000..7ba5cc3 --- /dev/null +++ b/webcc/soap_globals.cc @@ -0,0 +1,13 @@ +#include "webcc/soap_globals.h" + +namespace webcc { + +const std::string kSoapAction = "SOAPAction"; + +// According to www.w3.org when placing SOAP messages in HTTP bodies, the HTTP +// Content-type header must be chosen as "application/soap+xml" [RFC 3902]. +// But in practice, many web servers cannot understand it. +// See: https://www.w3.org/TR/2007/REC-soap12-part0-20070427/#L26854 +const std::string kTextXmlUtf8 = "text/xml; charset=utf-8"; + +} // namespace webcc diff --git a/webcc/soap_globals.h b/webcc/soap_globals.h new file mode 100644 index 0000000..166f2be --- /dev/null +++ b/webcc/soap_globals.h @@ -0,0 +1,17 @@ +#ifndef WEBCC_SOAP_GLOBALS_H_ +#define WEBCC_SOAP_GLOBALS_H_ + +#include + +namespace webcc { + +// ----------------------------------------------------------------------------- +// Constants + +extern const std::string kSoapAction; + +extern const std::string kTextXmlUtf8; + +} // namespace webcc + +#endif // WEBCC_SOAP_GLOBALS_H_ diff --git a/webcc/soap_request_handler.cc b/webcc/soap_request_handler.cc index 77beb7a..943d27f 100644 --- a/webcc/soap_request_handler.cc +++ b/webcc/soap_request_handler.cc @@ -3,6 +3,7 @@ #include // for move() #include "webcc/logger.h" +#include "webcc/soap_globals.h" #include "webcc/soap_request.h" #include "webcc/soap_response.h" @@ -10,7 +11,6 @@ namespace webcc { bool SoapRequestHandler::Bind(SoapServicePtr service, const std::string& url) { assert(service); - url_service_map_[url] = service; return true; }