From 545c170d344336ba9d4b9517728242626d6dcbfe Mon Sep 17 00:00:00 2001 From: Arthur Britto Date: Tue, 3 Apr 2012 20:48:23 -0700 Subject: [PATCH] Make https regexes static. --- src/HttpsClient.cpp | 28 +++++++++++++++------------- src/HttpsClient.h | 3 ++- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/HttpsClient.cpp b/src/HttpsClient.cpp index f86c445fe8..117c9e3803 100644 --- a/src/HttpsClient.cpp +++ b/src/HttpsClient.cpp @@ -7,11 +7,10 @@ #include #include #include +#include #include #include -#include - using namespace boost::system; using namespace boost::asio; @@ -283,27 +282,30 @@ void HttpsClient::invokeComplete(const boost::system::error_code& ecResult, std: void HttpsClient::parseData() { - // AHB How does this work? - // http://stackoverflow.com/questions/877652/copy-a-streambufs-contents-to-a-string std::string strData((std::istreambuf_iterator(&mResponse)), std::istreambuf_iterator()); - // Match status code on a line. - boost::regex reStatus("\\`HTTP/1\\S+ (\\d{3}) .*\\'"); // HTTP/1.1 200 OK - - // Match body. - boost::regex reBody("\\`(?:.*\\r\\n\\r\\n){1,1}(.*)\\'"); + static boost::regex reStatus("\\`HTTP/1\\S+ (\\d{3}) .*\\'"); // HTTP/1.1 200 OK + static boost::regex reBody("\\`(?:.*?\\r\\n\\r\\n){1}(.*)\\'"); boost::smatch smMatch; - bool bMatch = boost::regex_match(strData, smMatch, reStatus) + bool bMatch = boost::regex_match(strData, smMatch, reStatus) // Match status code. && !smMatch[1].compare("200") - && boost::regex_match(strData, smMatch, reBody); + && boost::regex_match(strData, smMatch, reBody); // Match body. std::cerr << "Match: " << bMatch << std::endl; std::cerr << "Body:" << smMatch[1] << std::endl; - boost::system::error_code noErr; + if (bMatch) + { + boost::system::error_code noErr; - invokeComplete(noErr, smMatch[1]); + invokeComplete(noErr, smMatch[1]); + } + else + { + // XXX Use our own error code. + invokeComplete(boost::system::error_code(errc::bad_address, system_category())); + } } // vim:ts=4 diff --git a/src/HttpsClient.h b/src/HttpsClient.h index 876ae802ac..3c3c9c7cf2 100644 --- a/src/HttpsClient.h +++ b/src/HttpsClient.h @@ -6,9 +6,10 @@ #include #include #include +#include #include #include -#include + // // Async https client.