Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ChunkedContent処理のコードを正確にチャンクサイズを読み込むタイプに変更した

ストリームAPIはコールバック関数を用いて実装することにした
  • Loading branch information...
commit cd5118f8d43c10225d29b5f6bbb7fe508552eaf7 1 parent f6e52ee
@gplusnasite gplusnasite authored
View
1  Include/AttachedInfo/AttachedAlbum/AttachedAlbum.hpp
@@ -16,6 +16,7 @@
#endif
#endif
+#include <memory>
#include <string>
#include <list>
View
1  Include/Circle/Circle.hpp
@@ -16,6 +16,7 @@
#endif
#endif
+#include <memory>
#include <string>
#include <map>
View
4 LuaScript/StreamInitialize.lua
@@ -33,7 +33,7 @@ function streamInitialize(account_id)
do return false end
end
- url = "https://talkgadget.google.com/talkgadget/channel/bind?VER=8&"
+ url = "https://talkgadget.google.com/u/0/talkgadget/_/channel/bind?VER=8&"
url = url .. "clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&prop=homepage&ujidr=TalkGadget" .. talkgadget_number .. "&"
url = url .. "eid&ec=" .. Connection.escapeString("[0,0,0]") .. "&RID=" .. generateRIDValue() .. "&CVER=1&zx=" .. generateZxString() .. "&t=1"
@@ -67,7 +67,7 @@ function streamInitialize(account_id)
print("Stream connecting ...")
- url = "https://talkgadget.google.com/talkgadget/channel/bind?VER=8&clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&"
+ url = "https://talkgadget.google.com/u/0/talkgadget/_/channel/bind?VER=8&clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&"
url = url .. "prop=homepage&ujidr=TalkGadget" .. talkgadget_number .. "&eid&ec=" .. Connection.escapeString("[0,0,0]") .. "&"
url = url .. "SID=" .. sid .. "&RID=" .. generateRIDValue() .. "&AID=2&zx=" .. generateZxString() .. "&t=1"
View
4 LuaScript/StreamLoopUpdate.lua
@@ -47,7 +47,7 @@ function streamLoopUpdate(account_id)
connection = Connection()
connection:setCurrentAccountID(account_id)
- url = "https://talkgadget.google.com/talkgadget/channel/bind?VER=8&clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&"
+ url = "https://talkgadget.google.com/u/0/talkgadget/_/channel/bind?VER=8&clid=" .. clid .. "&gsessionid=" .. gsessionid .. "&"
url = url .. "prop=homepage&ujidr=TalkGadget" .. talkgadget_number .. "&eid&ec=" .. Connection.escapeString("[0,0,0]") .. "&"
url = url .. "RID=rpc&SID=" .. sid .. "&CI=0&AID=" .. aid .. "&TYPE=xmlhttp&zx=" .. generateZxString() .. "&t=1"
@@ -55,7 +55,7 @@ function streamLoopUpdate(account_id)
response_body = response:getResponseBody()
- print("response_body:" .. response_body)
+ --print("response_body:" .. response_body)
status = response:getStatusCode()
if(status ~= 200) then
View
6 Project/MSVC/Win32/GooglePlusLibrary.vcxproj
@@ -62,7 +62,7 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalDependencies>lua5.1.lib;GooglePlusJsonParser.lib;cppnetlib-client-connectionsd.lib;cppnetlib-urid.lib;libeay32MDd.lib;ssleay32MDd.lib;libluabind_s_mdd.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>lua5.1.lib;GooglePlusJsonParser.lib;libeay32MDd.lib;ssleay32MDd.lib;libluabind_s_mdd.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\boost_1_52_0\stage\lib;C:\lua\lib;C:\OpenSSL-Win32\lib\VC\static;C:\luabind\bin\msvc-10.0\debug\link-static\threading-multi;D:\Development\GooglePlusLibrary\Src\Json\Debug;D:\Development\GooglePlusLibrary\Src\Connection\ChunkedContentParser\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
@@ -86,7 +86,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
- <AdditionalDependencies>lua5.1.lib;GooglePlusJsonParser.lib;cppnetlib-client-connections.lib;cppnetlib-uri.lib;libeay32MD.lib;ssleay32MD.lib;libluabind_s_md.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalDependencies>lua5.1.lib;GooglePlusJsonParser.lib;libeay32MD.lib;ssleay32MD.lib;libluabind_s_md.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\boost_1_52_0\stage\lib;C:\lua\lib;C:\OpenSSL-Win32\lib\VC\static;C:\luabind\bin\msvc-10.0\release\link-static\threading-multi;D:\Development\GooglePlusLibrary\Src\Json\Release;D:\Development\GooglePlusLibrary\Src\Connection\ChunkedContentParser\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<PostBuildEvent>
@@ -140,7 +140,6 @@
<ClCompile Include="..\..\..\Src\Connection\Talkgadget\TalkgadgetConnection.cpp" />
<ClCompile Include="..\..\..\Src\Connection\Uri.cpp" />
<ClCompile Include="..\..\..\Src\Connection\WebClient\WebClient.cpp" />
- <ClCompile Include="..\..\..\Src\Connection\WebClient\WebClientCppNetlib.cpp" />
<ClCompile Include="..\..\..\Src\Connection\WebClient\WebClientHandler.cpp" />
<ClCompile Include="..\..\..\Src\Hangout\GroupChat.cpp" />
<ClCompile Include="..\..\..\Src\Hangout\Hangout.cpp" />
@@ -261,7 +260,6 @@
<ClInclude Include="..\..\..\Src\Connection\Talkgadget\TalkgadgetConnection.hpp" />
<ClInclude Include="..\..\..\Src\Connection\Uri.hpp" />
<ClInclude Include="..\..\..\Src\Connection\WebClient\WebClient.hpp" />
- <ClInclude Include="..\..\..\Src\Connection\WebClient\WebClientCppNetlib.hpp" />
<ClInclude Include="..\..\..\Src\Hangout\HangoutConnection.hpp" />
<ClInclude Include="..\..\..\Src\Information\InformationContainer.hpp" />
<ClInclude Include="..\..\..\Src\Stream\Comment\CommentBase.hpp" />
View
6 Project/MSVC/Win32/GooglePlusLibrary.vcxproj.filters
@@ -256,9 +256,6 @@
<ClCompile Include="..\..\..\Src\Stream\StreamImpl.cpp">
<Filter>Stream</Filter>
</ClCompile>
- <ClCompile Include="..\..\..\Src\Connection\WebClient\WebClientCppNetlib.cpp">
- <Filter>Connection\WebClient</Filter>
- </ClCompile>
<ClCompile Include="..\..\..\Src\Utility\UtilityImpl.cpp">
<Filter>Utility</Filter>
</ClCompile>
@@ -657,9 +654,6 @@
<ClInclude Include="..\..\..\Include\Stream\StreamImpl.hpp">
<Filter>Stream</Filter>
</ClInclude>
- <ClInclude Include="..\..\..\Src\Connection\WebClient\WebClientCppNetlib.hpp">
- <Filter>Connection\WebClient</Filter>
- </ClInclude>
<ClInclude Include="..\..\..\Src\Utility\UtilityImpl.hpp">
<Filter>Utility</Filter>
</ClInclude>
View
56 Src/Connection/HttpResponse.cpp
@@ -13,7 +13,6 @@ namespace GooglePlusLibrary
using namespace std;
using namespace ::luabind;
-namespace http = boost::network::http;
HttpResponse::HttpResponse()
:url_(""),
@@ -55,61 +54,6 @@ response_cookie_(response_cookie)
}
}
-HttpResponse::HttpResponse(const string& url, const http::client::response& response)
-:url_(url),
-status_code_(status(response)),
-response_body_(body(response)),
-response_header_(),
-response_cookie_(),
-redirect_url_("")
-{
- cout << "Get or Post End" << endl;
-
- auto it = headers(response).begin();
- while(it != headers(response).end())
- {
- if(it->first == "Set-Cookie")
- {
- Cookie cookie(url_, it->second);
- response_cookie_.push_back(cookie);
- }
- else
- {
- if(it->first == "Location")
- {
- redirect_url_ = it->second;
-
- string scheme = redirect_url_.substr(0, 4);
- if(scheme != "http")
- {
- boost::network::uri::uri uri(url);
- string target = uri.scheme() + "://" + uri.host();
- redirect_url_ = target + redirect_url_;
- }
- }
- response_header_.insert(map<string, string>::value_type(it->first, it->second));
- }
- ++it;
- }
-
- //cout << "response:" << response_body_ << endl;
- /*
- if((getStatusCode() == 200) && (getResponseHeaderValue("Transfer-Encoding") == "chunked"))
- {
- ChunkedContentParser parser;
- bool result = parser.parse(response_body_);
- if(result)
- {
- response_body_ = parser.getResult();
- }
- else
- {
- cout << "Parse Failed" << endl;
- }
- }
- */
-}
-
string HttpResponse::getUrl() const
{
return url_;
View
6 Src/Connection/HttpResponse.hpp
@@ -18,8 +18,6 @@
#endif
#endif
-#include <boost/network/protocol/http/client.hpp>
-
#include <string>
#include <map>
#include <list>
@@ -54,9 +52,7 @@ class GOOGLEPLUSLIBRARY_API HttpResponse
HttpResponse(const std::string& url, int status_code, const std::map<std::string, std::string>& response_header,
const std::list<Cookie>& response_cookie,
const std::string& response_body);
-
- HttpResponse(const std::string& url, const boost::network::http::client::response& response);
-
+
public:
std::string getUrl() const;
private:
View
6 Src/Connection/WebClient/WebClient.cpp
@@ -33,7 +33,7 @@ method_("GET"),
response_body_(""),
url_(url),
path_(""),
-request_stream_(),
+request_(),
response_(),
content_(""),
content_type_(""),
@@ -85,8 +85,6 @@ status_code_(0)
boost::bind(&WebClient::handleResolve, this,
boost::asio::placeholders::error,
boost::asio::placeholders::iterator));
-
- connect_timer_.async_wait(boost::bind(&WebClient::checkDeadLine, this));
}
void WebClient::setCurrentMailAddress(const string& mail_address)
@@ -363,7 +361,7 @@ void WebClient::setTimeOut(boost::posix_time::seconds time)
void WebClient::sendRequest()
{
- request_stream_ = setRequestStream();
+ request_ = setRequestStream();
io_service_.run();
}
View
13 Src/Connection/WebClient/WebClient.hpp
@@ -109,7 +109,7 @@ class GOOGLEPLUSLIBRARY_API WebClient
protected:
- std::stringstream setRequestStream();
+ std::string setRequestStream();
void checkDeadLine();
@@ -134,14 +134,8 @@ class GOOGLEPLUSLIBRARY_API WebClient
void handleReadContent(const boost_error_code& error, size_t bytes_transferred);
void startReadChunkedContent();
-
void handleReadChunkSize(const boost_error_code& error, size_t bytes_transferred);
- void handleReadChunkSize2(const boost_error_code& error, size_t bytes_transferred);
- void handleReadEndSize(const boost_error_code& error, size_t bytes_transferred);
- void handleReadEndLine(const boost_error_code& error, size_t bytes_transferred);
- void handleReadChunkedContent(const boost_error_code& error, size_t bytes_transferred);
- void handleReadChunkedContent2(const boost_error_code& error, size_t bytes_transferred);
- void handleReadChunkedContent3(const boost_error_code& error, size_t bytes_transferred);
+ void handleReadChunkData(const boost_error_code& error, size_t bytes_transferred);
private:
std::shared_ptr<boost::asio::io_service> io_service_ptr_;
boost::asio::io_service& io_service_;
@@ -156,10 +150,11 @@ class GOOGLEPLUSLIBRARY_API WebClient
std::string method_;
std::map<std::string, std::string> response_headers_;
+ std::size_t chunk_remain_;
std::string response_body_;
std::string url_;
std::string path_;
- std::stringstream request_stream_;
+ std::string request_;
//size_t content_length_;
std::string content_;
View
542 Src/Connection/WebClient/WebClientHandler.cpp
@@ -4,12 +4,12 @@
#include <boost/bind.hpp>
#include <boost/algorithm/string/trim.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/phoenix.hpp>
-#include <boost/regex.hpp>
#include <iostream>
#include <fstream>
+#include <algorithm>
+
+//#define DEBUG_WITH_HEXDUMP
namespace Gplusnasite
{
@@ -19,8 +19,55 @@ namespace GooglePlusLibrary
using namespace std;
using namespace boost::asio::ssl;
using namespace boost::asio::ip;
-namespace qi = boost::spirit::qi;
-namespace phoenix = boost::phoenix;
+
+#if defined DEBUG_WITH_HEXDUMP
+
+static void hexdump(const char *buf, size_t len)
+{
+
+ // xxxxxxx aa aa aa aa aa aa aa aa:aa aa aa aa aa aa aa aa|aaaaaaaaaaaaaaaa
+
+ char line[] = "0000000 : | ";
+
+ static const char hc[] = "0123456789abcdef";
+
+ for (size_t i = 0; i < len; ++i) {
+
+ int c = (unsigned char)buf[i];
+
+ size_t offset = i % 16;
+
+ if (offset == 0) {
+
+ if (i != 0)
+
+ puts(line);
+
+ sprintf(line, "%07x", (unsigned int)i);
+
+ memset(line + 7, ' ', sizeof line - 8);
+
+ line[31] = ':';
+
+ line[55] = '|';
+
+ }
+
+ char *p = line + 8 + offset * 3;
+
+ p[0] = hc[(c >> 4) & 0xfU];
+
+ p[1] = hc[c & 0xfU];
+
+ line[56 + offset] = isprint(c) ? c : ' ';
+
+ }
+
+ puts(line);
+
+}
+
+#endif //DEBUG_WITH_HEXDUMP
void WebClient::handleConnectTimeout(const boost_error_code& error)
{
@@ -41,7 +88,6 @@ void WebClient::handleResolve(const boost_error_code& error, asio_resolver::iter
return;
}
startConnect(endpoint_iterator);
- connect_timer_.async_wait(boost::bind(&WebClient::checkDeadLine, this));
}
void WebClient::startConnect(tcp::resolver::iterator endpoint_iterator)
@@ -96,10 +142,11 @@ void WebClient::handleConnect(const boost_error_code& error, tcp::resolver::iter
}
}
-stringstream WebClient::setRequestStream()
+string WebClient::setRequestStream()
{
stringstream request_stream;
+ //cout << "method: " << method_ << ", path: " << path_ << endl; //XXX
request_stream << method_ << " " << path_ << " HTTP/1.1\r\n";
auto request_header_it = request_headers_.cbegin();
@@ -146,7 +193,7 @@ stringstream WebClient::setRequestStream()
{
request_stream << content_;
}
- return request_stream;
+ return request_stream.str();
}
void WebClient::handleHandshake(const boost_error_code& error)
@@ -165,7 +212,7 @@ void WebClient::startWrite()
}
boost::asio::async_write(socket_,
- boost::asio::buffer(request_stream_.str().c_str(), strlen(request_stream_.str().c_str())),
+ boost::asio::buffer(request_.c_str(), strlen(request_.c_str())),
boost::bind(&WebClient::handleWrite, this, boost::asio::placeholders::error));
}
@@ -182,8 +229,6 @@ void WebClient::handleWrite(const boost_error_code& error)
cancelConnect();
return;
}
- heartbeat_timer_.expires_from_now(boost::posix_time::seconds(10));
- heartbeat_timer_.async_wait(boost::bind(&WebClient::startWrite, this));
}
void WebClient::handleReadStatusLine(const boost_error_code& error)
@@ -257,7 +302,7 @@ void WebClient::handleReadHeaders(const boost_error_code& error)
cookies.push_back(cookie);
}
response_headers_.insert(make_pair(name, value));
- //cout << "header:" << name << "=" << value << endl;
+ //cout << "header:" << name << "=" << value << endl; //XXX
}
response_cookies_ = cookies;
@@ -275,7 +320,7 @@ void WebClient::handleReadHeaders(const boost_error_code& error)
{
size_t size = boost::lexical_cast<size_t>(length);
boost::asio::async_read(socket_, response_,
- boost::asio::transfer_exactly(size),
+ boost::asio::transfer_exactly(size - response_.size()),
boost::bind(&WebClient::handleReadContent, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)
@@ -294,392 +339,205 @@ void WebClient::handleReadHeaders(const boost_error_code& error)
void WebClient::startReadChunkedContent()
{
- //cout << "LoadHandleReadChunkSize" << endl;
-
- connect_timer_.expires_from_now(boost::posix_time::seconds(30));
- /*
- boost::asio::async_read_until(socket_, response_, "\n",
- boost::bind(&WebClient::handleReadChunkSize, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
- */
-
- boost::asio::async_read_until(socket_, response_, "\n",
- boost::bind(&WebClient::handleReadChunkedContent, this,
+ boost::asio::async_read_until(socket_, response_, "\r\n",
+ boost::bind(&WebClient::handleReadChunkSize, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
+}
+static size_t hex2size_t(const std::string str)
+{
+ size_t size = 0;
+ for (const char *p = str.c_str(); *p; ++p) {
+ switch (*p) {
+ // case '0': break; // nothing to do
+ case '1':
+ size += 1;
+ break;
+ case '2':
+ size += 2;
+ break;
+ case '3':
+ size += 3;
+ break;
+ case '4':
+ size += 4;
+ break;
+ case '5':
+ size += 5;
+ break;
+ case '6':
+ size += 6;
+ break;
+ case '7':
+ size += 7;
+ break;
+ case '8':
+ size += 8;
+ break;
+ case '9':
+ size += 9;
+ break;
+ case 'A':
+ case 'a':
+ size += 10;
+ break;
+ case 'B':
+ case 'b':
+ size += 11;
+ break;
+ case 'C':
+ case 'c':
+ size += 12;
+ break;
+ case 'D':
+ case 'd':
+ size += 13;
+ break;
+ case 'E':
+ case 'e':
+ size += 14;
+ break;
+ case 'F':
+ case 'f':
+ size += 15;
+ break;
+ default:
+ // nothing to do
+ break;
+ }
+ if ('\0' == p[1])
+ break;
+ size <<= 4;
+ }
+
+ return size;
}
+
void WebClient::handleReadChunkSize(const boost_error_code& error, size_t bytes_transferred)
{
- cout << "HandleReadChunkSize" << endl;
-
if (is_cancellation_pending_)
{
- cancelConnect();
- return;
- }
-
- if (error)
- {
- cout << "Error on receive: " << error.message() << endl;
- cancelConnect();
return;
}
- string line = string(boost::asio::buffer_cast<const char*>(response_.data()), bytes_transferred);
- response_.consume(bytes_transferred);
+ //cout << "handleReadChunkSize" << endl;
+ //cout << "URL:" << url_ << endl;
- size_t size = -1;
+#if defined DEBUG_WITH_HEXDUMP
+ hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
+ bytes_transferred);
+#endif /* DEBUG_WITH_HEXDUMP */
- if(qi::parse(line.cbegin(), line.cend(), qi::hex[phoenix::ref(size) = qi::_1] >> (qi::lit("\r\n") | qi::lit("\n"))))
- {
- if(size == 0)
- {
- cancelConnect();
- }
- else
- {
- cout << "LoadHandleReadChunkedContent" << endl;
- cout << "Chunk Size:" <<size << endl;
-
- boost::asio::async_read(socket_, response_,
- boost::asio::transfer_exactly(size),
- boost::bind(&WebClient::handleReadChunkedContent3, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
- }
- }
- else
- {
+ if (error) {
+ cout << "error on receive: " << error.message() << endl;
cancelConnect();
- }
-}
-
-void WebClient::handleReadChunkSize2(const boost_error_code& error, size_t bytes_transferred)
-{
- //cout << "HandleReadChunkSize" << endl;
-
- if (is_cancellation_pending_)
- {
return;
}
- if (error)
+ std::string response(boost::asio::buffer_cast<const char*>(response_.data()), response_.size());
+ std::string eol("\r\n");
+ std::size_t pos_eol = response.find(eol);
+ if (std::string::npos == pos_eol)
{
- cout << "Error on receive: " << error.message() << endl;
+ cout << " error on receive: bad chunk format." << endl;
cancelConnect();
return;
}
-
- string line = string(boost::asio::buffer_cast<const char*>(response_.data()), bytes_transferred);
- response_.consume(bytes_transferred);
- if(line.find("0\r\n") >= 0)
- {
- int a = 3;
- }
- int size = -1;
+ std::size_t line_length = pos_eol + eol.size();
- if(qi::parse(line.cbegin(), line.cend(), qi::hex[phoenix::ref(size) = qi::_1] >> (qi::lit("\r\n") | qi::lit("\n"))))
- {
- if(size == 0)
- {
- cout << "handleReadChunkSize2 size == 0----------------------------------------------------------------" << endl;
- cancelConnect();
- return;
- }
- read_size_ = size;
- //read_mode_ = ReadEndSize;
- read_mode_ = ReadChunkedContent;
- startReadChunkedContent();
- }
- else
- {
- cout << "handleReadChunkSize2 parse failed----------------------------------------------------------------" << endl;
- cancelConnect();
- return;
- }
-
-}
+ string chunk_size_line(boost::asio::buffer_cast<const char*>(response_.data()), line_length);
+ response_.consume(line_length);
-void WebClient::handleReadEndSize(const boost_error_code& error, size_t bytes_transferred)
-{
- //cout << "HandleReadEndSize" << endl;
+ chunk_size_line.resize(chunk_size_line.length() - 2 /* drop "\r\n" */);
- if (is_cancellation_pending_)
+ if (0 == chunk_size_line.length())
{
- return;
+ // no more chunk.
+ cancelConnect();
}
- if (error)
+ size_t chunk_size = hex2size_t(chunk_size_line);
+ if (0 == chunk_size)
{
- cout << "Error on receive: " << error.message() << endl;
- cancelConnect();
+ // wait next chunk.
+ startReadChunkedContent();
return;
}
- string line = string(boost::asio::buffer_cast<const char*>(response_.data()), bytes_transferred);
- response_.consume(bytes_transferred);
- if(line.find("0\r\n") >= 0)
- {
- int a = 3;
- }
- read_size_ -= bytes_transferred;
+ chunk_size += 2; // for trailing CRLF
+ chunk_remain_ = chunk_size;
- int end_size = -1;
- /*
- if(qi::parse(line.cbegin(), line.cend(), qi::hex[phoenix::ref(end_size) = qi::_1] >> (qi::lit("\r\n") | qi::lit("\n"))))
- {
- if(end_size > 0)
- {
- read_end_size_ = end_size;
- }
- else
- {
- response_body_ += line;
- }
- }
- else
- {
- response_body_ += line;
- }
- */
- response_body_ += line;
+ std::size_t size_to_need = 0;
+ if (response_.size() < chunk_size)
+ size_to_need = chunk_size - response_.size();
- read_mode_ = ReadChunkedContent;
- startReadChunkedContent();
+ boost::asio::async_read(socket_,
+ response_,
+ boost::asio::transfer_exactly(size_to_need),
+ boost::bind(&WebClient::handleReadChunkData, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
}
-void WebClient::handleReadEndLine(const boost_error_code& error, size_t bytes_transferred)
+void WebClient::handleReadChunkData(const boost_error_code& error, size_t bytes_transferred)
{
- cout << "HandleReadChunkSize" << endl;
- string raw_line = string(boost::asio::buffer_cast<const char*>(response_.data()), bytes_transferred);
- if(raw_line != "\r\n")
- {
- cout << "End Line:" << raw_line << endl;
- }
- response_.consume(bytes_transferred);
- /*
- int size = response_.size();
- if(size == 0)
+ if (is_cancellation_pending_)
{
- cancelConnect();
return;
}
- */
- startReadChunkedContent();
-}
-
-void WebClient::handleReadChunkedContent2(const boost_error_code& error, size_t bytes_transferred)
-{
- if (is_cancellation_pending_)
- return;
- if (!error)
- {
- string line("");
- /*
- istream is(&response_);
+ //cout << "handleReadChunkData" << endl;
+ //cout << "URL:" << url_ << endl;
- if(!(getline(is, line) && line != "\r"))
- {
- //cout << "-------------------------------------------------------------------" << endl;
- cancelConnect();
- return;
- }
- */
- string aa = string(boost::asio::buffer_cast<const char*>(response_.data()), response_.size());
- line = string(boost::asio::buffer_cast<const char*>(response_.data()), bytes_transferred);
- int position = line.find("\n");
- if(position < 0)
- {
- cout << "1-------------------------------------------------------------------" << endl;
- cancelConnect();
- return;
- }
-
- line = line.substr(0, position + 1);
- response_.consume(line.size());
- /*
- int size = response_.size();
- if(size <= 0)
- {
- //cout << "response_.size() = 0" << endl;
- cancelConnect();
- return;
- }
- */
- if((response_.size() <= 0) && (line == "\r\n"))
- {
- cout << "2-------------------------------------------------------------------" << endl;
- cancelConnect();
- return;
- }
-
- if(!qi::parse(line.cbegin(), line.cend(), qi::hex >> (qi::lit("\r\n") | qi::lit("\n"))))
- {
- // line is chunk size
- response_body_ += line;
- }
- /*
- boost::regex regex("([0-9a-zA-Z]+)\\r\\n");
- boost::smatch smatch;
+#if defined DEBUG_WITH_HEXDUMP
+ hexdump(boost::asio::buffer_cast<const char*>(response_.data()),
+ response_.size());
+#endif /* DEBUG_WITH_HEXDUMP */
- if(boost::regex_search(line, smatch, regex))
- {
- int position = smatch.position();
- if(smatch.position() != 0)
- {
- response_body_ += line;
- }
- else
- {
- int a = 3;
- }
- }
- else
- {
- response_body_ += line;
- }
- */
- startReadChunkedContent();
- }
- else
- {
- cout << "Error on receive: " << error.message() << L"\n";
+ if (error) {
+ cout << "error on receive: " << error.message() << endl;
cancelConnect();
}
-}
-void WebClient::handleReadChunkedContent(const boost_error_code& error, size_t bytes_transferred)
-{
- if (is_cancellation_pending_)
- return;
+ std::size_t eat_size = std::min(chunk_remain_, response_.size());
- if (!error)
+ string res(boost::asio::buffer_cast<const char*>(response_.data()), eat_size);
+ if(url_.substr(0, 59) == "https://talkgadget.google.com/u/0/talkgadget/_/channel/bind")
{
- string line("");
- string aa = string(boost::asio::buffer_cast<const char*>(response_.data()), response_.size());
- line = string(boost::asio::buffer_cast<const char*>(response_.data()), bytes_transferred);
- response_.consume(bytes_transferred);
-
- if(line == "\r\n")
- {
- cancelConnect();
- return;
- }
- /*
- if((response_.size() <= 0) && (line == "\r\n"))
- {
- cancelConnect();
- return;
- }
- */
- /*
- if(!qi::parse(line.cbegin(), line.cend(), qi::hex >> (qi::lit("\r\n") | qi::lit("\n"))))
- {
- // line is chunk size
- response_body_ += line;
- }
- */
-
- boost::regex regex("([0-9a-zA-Z]+)\\r\\n");
- boost::smatch smatch;
+ cout << "response:" << res << endl;
+ }
- if(boost::regex_search(line, smatch, regex))
- {
- if(smatch.position() != 0)
- {
- response_body_ += line;
- }
- }
- else
- {
- response_body_ += line;
- }
+ response_body_.append(boost::asio::buffer_cast<const char*>(response_.data()), eat_size);
- startReadChunkedContent();
- /*
- boost::asio::async_read_until(socket_, response_, "\n",
- boost::bind(&WebClient::handleReadEndLine, this,
- _1, _2));
- */
- }
- else
- {
- cout << "Error on receive: " << error.message() << L"\n";
- cancelConnect();
- }
-}
+ response_.consume(eat_size);
+ chunk_remain_ -= eat_size;
-void WebClient::handleReadChunkedContent3(const boost_error_code& error, size_t bytes_transferred)
-{
- if (is_cancellation_pending_)
- {
- cancelConnect();
+ if (chunk_remain_ > 0) {
+ boost::asio::async_read(socket_,
+ response_,
+ boost::asio::transfer_exactly(chunk_remain_),
+ boost::bind(&WebClient::handleReadChunkData, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
return;
}
- if (!error)
- {
- string line("");
- string aa = string(boost::asio::buffer_cast<const char*>(response_.data()), response_.size());
- line = string(boost::asio::buffer_cast<const char*>(response_.data()), bytes_transferred);
- response_.consume(bytes_transferred);
-
- if(line == "\r\n")
- {
- cancelConnect();
- return;
- }
- /*
- if((response_.size() <= 0) && (line == "\r\n"))
- {
- cancelConnect();
- return;
- }
- */
-
- if(qi::parse(line.cbegin(), line.cend(), qi::hex >> (qi::lit("\r\n") | qi::lit("\n")) >> qi::as_string[*qi::char_][phoenix::ref(response_body_) += qi::_1]))
- {
- // stream response
- cancelConnect();
- return;
- }
- else
- {
- response_body_ += line;
- }
+ response_body_.resize(response_body_.size() - 2 /* drop trailing "\r\n" */);
- /*
- boost::regex regex("([0-9a-zA-Z]+)\\r\\n");
- boost::smatch smatch;
-
- if(boost::regex_search(line, smatch, regex))
- {
- if(smatch.position() != 0)
- {
- response_body_ += line;
- }
- }
- else
- {
- response_body_ += line;
- }
- */
- //startReadChunkedContent();
-
- boost::asio::async_read_until(socket_, response_, "\n",
- boost::bind(&WebClient::handleReadEndLine, this,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred));
- }
- else
+ if (response_.size() > 0)
{
- cout << "Error on receive: " << error.message() << L"\n";
- cancelConnect();
+ boost::asio::async_read(socket_, response_,
+ boost::asio::transfer_exactly(0),
+ boost::bind(&WebClient::handleReadChunkSize, this,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred));
+ return;
}
+
+ // will be trying to read some chunks remaining.
+ startReadChunkedContent();
}
void WebClient::handleReadContent(const boost_error_code& error, size_t bytes_transferred)
View
1  Src/Hangout/HangoutList.cpp
@@ -3,7 +3,6 @@
#include <Utility/Utility.hpp>
#include <Connection/Connection.hpp>
#include <Connection/Cookie/Cookie.hpp>
-#include <Connection/HttpResponse.hpp>
#include <Information/InformationContainer.hpp>
#include <Hangout/HangoutConnection.hpp>
#include <Json/JsonObject.hpp>
View
BIN  Src/Json/GooglePlusJsonParser.suo
Binary file not shown
View
8 Src/Json/GooglePlusJsonParser.vcxproj
@@ -62,14 +62,14 @@
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>C:\boost_1_51_0;C:\lua5_1_4_Win32_dll8_lib\include;C:\luabind;D:\Development\GooglePlusLibrary\Src;D:\Development\utf8_v2_3_2\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>C:\boost_1_52_0;C:\lua\include;C:\luabind;D:\Development\GooglePlusLibrary\Src;D:\Development\utf8_v2_3_2\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
<Lib>
- <AdditionalLibraryDirectories>C:\boost_1_51_0\stage\lib;C:\lua5_1_4_Win32_dll8_lib;C:\luabind\bin\msvc-10.0\debug\link-static\threading-multi;D:\Development\JsonParserTest\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>C:\boost_1_52_0\stage\lib;C:\lua\lib;C:\luabind\bin\msvc-10.0\debug\link-static\threading-multi;D:\Development\JsonParserTest\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
@@ -82,7 +82,7 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <AdditionalIncludeDirectories>C:\boost_1_51_0;C:\lua5_1_4_Win32_dll8_lib\include;C:\luabind;D:\Development\GooglePlusLibrary\Src;D:\Development\utf8_v2_3_2\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>C:\boost_1_52_0;C:\lua\include;C:\luabind;D:\Development\GooglePlusLibrary\Src;D:\Development\utf8_v2_3_2\source;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
@@ -91,7 +91,7 @@
<OptimizeReferences>true</OptimizeReferences>
</Link>
<Lib>
- <AdditionalLibraryDirectories>C:\boost_1_51_0\stage\lib;C:\lua5_1_4_Win32_dll8_lib;C:\luabind\bin\msvc-10.0\release\link-static\threading-multi;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+ <AdditionalLibraryDirectories>C:\boost_1_52_0\stage\lib;C:\lua\lib;C:\luabind\bin\msvc-10.0\release\link-static\threading-multi;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
</Lib>
</ItemDefinitionGroup>
View
14 Src/Json/JsonObject.cpp
@@ -208,13 +208,13 @@ wstring JsonObject::getTypeAsWString() const
assert(impl_);
switch(impl_->type_)
{
- case ObjectType::Null: return L"Null";
- case ObjectType::Int: return L"Int";
- case ObjectType::Real: return L"Real";
- case ObjectType::Bool: return L"Bool";
- case ObjectType::Array: return L"Array";
- case ObjectType::Object: return L"Object";
- case ObjectType::String: return L"String";
+ case JsonObjectImpl::ObjectImplType::Null: return L"Null";
+ case JsonObjectImpl::ObjectImplType::Int: return L"Int";
+ case JsonObjectImpl::ObjectImplType::Real: return L"Real";
+ case JsonObjectImpl::ObjectImplType::Bool: return L"Bool";
+ case JsonObjectImpl::ObjectImplType::Array: return L"Array";
+ case JsonObjectImpl::ObjectImplType::Object: return L"Object";
+ case JsonObjectImpl::ObjectImplType::String: return L"String";
}
return L"Unknown";
}
View
5 Src/Json/JsonParser.cpp
@@ -42,6 +42,7 @@ JsonObject JsonParser::parse(const wstring& json) const
cout << "JsonParser:ParseFailed" << endl;
#endif
+#ifdef LOGGING
wstringstream string_stream;
string_stream << "FailedJson";
string_stream << count;
@@ -50,6 +51,7 @@ JsonObject JsonParser::parse(const wstring& json) const
json_file = _wfopen(string_stream.str().c_str(), L"w, ccs=UTF-16LE");
fwprintf(json_file, json.c_str());
fclose(json_file);
+#endif
}
}
catch (...)
@@ -57,6 +59,8 @@ JsonObject JsonParser::parse(const wstring& json) const
#ifdef TRACE
cout << "JsonParser:ParseFailed" << endl;
#endif
+
+#ifdef LOGGING
wstringstream string_stream;
string_stream << "Failed(Exception)Json";
string_stream << count;
@@ -66,6 +70,7 @@ JsonObject JsonParser::parse(const wstring& json) const
json_file = _wfopen(string_stream.str().c_str(), L"w, ccs=UTF-16LE");
fwprintf(json_file, json.c_str());
fclose(json_file);
+#endif
}
++count;
View
1  Src/Stream/Post/PostParser/PostParser.cpp
@@ -1,5 +1,6 @@
#include <Stream/Post/PostParser/PostParser.hpp>
#include <Stream/Post/PostContainer/PostContainer.hpp>
+#include <Json/JsonObject.hpp>
#include <Utility/Utility.hpp>
#include <Utility/LuaScript.hpp>
View
3  Src/Stream/StreamConnectionImplLua.cpp
@@ -25,13 +25,14 @@ void StreamConnectionImpl::initializeAsyncThreadMethod(const wstring& account_id
return;
}
- LuaScript<bool(string)> lua_script("LuaScript/StreamInitialize.lua", "streamInitialize", [](lua_State* lua_state)
+ LuaScript<bool(string)> lua_script("LuaScript/StreamInitialize.lua", "streamInitialize", [this](lua_State* lua_state)
{
Connection::bindToScript(lua_state);
HttpResponse::bindToScript(lua_state);
Utility::bindToScript(lua_state);
InformationContainer::bindToScript(lua_state);
JsonObject::bindToScript(lua_state);
+ bindToScript(lua_state);
});
lua_script.onLoadingScriptFailed.connect([&](string message)
Please sign in to comment.
Something went wrong with that request. Please try again.