removing a ton of debug code

pull/40/head
Matchman Green 2012-05-01 01:14:41 +08:00
parent 8df7382d91
commit e79ff1541c
3 changed files with 12 additions and 103 deletions

View File

@ -49,14 +49,9 @@ Drive::Drive( OAuth2& auth ) :
Json resp = Json::Parse( http::Get( root_url + "?alt=json&showfolders=true", m_http_hdr )) ;
std::cout << http::Get( "https://docs.google.com/feeds/metadata/default", m_http_hdr ) ;
Json resume_link ;
if ( resp["feed"]["link"].FindInArray( "rel", "http://schemas.google.com/g/2005#resumable-create-media", resume_link ) )
{
m_resume_link = resume_link["href"].As<std::string>() ;
std::cout << "resume_link = " << resume_link << std::endl ;
}
Json::Array entries = resp["feed"]["entry"].As<Json::Array>() ;
ConstructDirTree( entries ) ;
@ -238,14 +233,15 @@ void Drive::UploadFile( const Json& entry, const std::string& filename, std::str
(std::istreambuf_iterator<char>(file)),
(std::istreambuf_iterator<char>()) ) ;
std::ostringstream content_len ;
content_len << data.size() ;
std::ostringstream xcontent_len ;
xcontent_len << "X-Upload-Content-Length: " << data.size() ;
http::Headers hdr( m_http_hdr ) ;
// hdr.push_back( "Slug: Grive Document" ) ;
hdr.push_back( "Content-Type: application/atom+xml" ) ;
hdr.push_back( "X-Upload-Content-Type: text/plain" ) ;
hdr.push_back( "X-Upload-Content-Length: " + content_len.str() ) ;
hdr.push_back( "X-Upload-Content-Type: application/octet-stream" ) ;
hdr.push_back( xcontent_len.str() ) ;
hdr.push_back( "If-Match: " + entry["gd$etag"].As<std::string>() ) ;
hdr.push_back( "Expect:" ) ;
/* std::string resp = http::PostDataWithHeader(
@ -255,16 +251,9 @@ void Drive::UploadFile( const Json& entry, const std::string& filename, std::str
*/
Json resume_link = entry["link"].FindInArray( "rel",
"http://schemas.google.com/g/2005#resumable-edit-media" )["href"] ;
std::cout << resume_link.As<std::string>() << std::endl ;
// std::cout << resume_link.As<std::string>() << std::endl ;
std::string etag = entry["gd$etag"].As<std::string>() ;
std::cout << "etag = " << etag << std::endl ;
hdr.push_back( "If-Match: " + etag ) ;
std::string resp = http::Put( resume_link.Get(), meta, hdr ) ;
std::cout << "resp " << resp << std::endl ;
std::istringstream ss( resp ) ;
std::istringstream ss( http::Put( resume_link.Get(), meta, hdr ) ) ;
std::string line ;
while ( std::getline( ss, line ) )
@ -276,13 +265,12 @@ void Drive::UploadFile( const Json& entry, const std::string& filename, std::str
uplink = uplink.substr( 0, uplink.size() -1 ) ;
http::Headers uphdr ;
uphdr.push_back( "Content-Type: text/plain" ) ;
// uphdr.push_back( "Content-Type: application/octet-stream" ) ;
// uphdr.push_back( "Content-Range: bytes 0-999/1000" ) ;
uphdr.push_back( "Expect:" ) ;
uphdr.push_back( "Accept:" ) ;
std::string resp = http::Put( uplink, data, uphdr ) ;
std::cout << "put response = " << resp << std::endl ;
http::Put( uplink, data, uphdr ) ;
}
}
}

View File

@ -51,16 +51,12 @@ size_t ReadCallback( void *ptr, std::size_t size, std::size_t nmemb, std::string
assert( ptr != 0 ) ;
assert( data != 0 ) ;
std::cout << "reading " << (size*nmemb) << " bytes " << data->size() << std::endl ;
std::size_t count = std::min( size * nmemb, data->size() ) ;
if ( count > 0 )
{
std::memcpy( ptr, &(*data)[0], count ) ;
data->erase( 0, count ) ;
}
std::cout << "readed " << count << " bytes " << data->size() << std::endl ;
return count ;
}
@ -170,7 +166,7 @@ std::string PostData( const std::string& url, const std::string& data, const Hea
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, &post_data[0] ) ;
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, post_data.size() ) ;
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1 ) ;
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1 ) ;
DoCurl( curl ) ;
return resp;
@ -186,7 +182,7 @@ std::string PostDataWithHeader( const std::string& url, const std::string& data,
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, &post_data[0] ) ;
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, post_data.size() ) ;
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L ) ;
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L ) ;
curl_easy_setopt(curl, CURLOPT_HEADER, 1L );
try
@ -224,7 +220,7 @@ std::string Put(
curl_easy_setopt(curl, CURLOPT_READFUNCTION, &ReadCallback ) ;
curl_easy_setopt(curl, CURLOPT_READDATA , &put_data ) ;
curl_easy_setopt(curl, CURLOPT_INFILESIZE, put_data.size() ) ;
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L ) ;
// curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L ) ;
try
{
@ -239,79 +235,6 @@ std::string Put(
return resp;
}
void Custom( const std::string& url, const std::string& host, const Headers& headers )
{
CURL *curl = curl_easy_init();
if ( curl == 0 )
throw std::bad_alloc() ;
// set common options
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 1L );
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L ) ;
if ( curl_easy_perform( curl ) != 0 )
throw std::runtime_error( "curl perform fail" ) ;
long sockextr;
curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);
curl_socket_t sockfd = sockextr ;
struct timeval tv;
tv.tv_sec = 60 ;
tv.tv_usec = 0 ;
fd_set infd, outfd, errfd;
FD_ZERO(&infd);
FD_ZERO(&outfd);
FD_ZERO(&errfd);
FD_SET(sockfd, &errfd); /* always check for error */
FD_SET(sockfd, &outfd);
if ( select(sockfd + 1, &infd, &outfd, &errfd, &tv) == -1 )
throw std::runtime_error( "select fail" ) ;
std::string path = url.substr( host.size() ) ;
std::cout << ("PUT " + path + "HTTP/1.1") << std::endl ;
std::ostringstream req ;
req << ("PUT " + path + "HTTP/1.1\n")
<< "Host: " << "docs.google.com" << "\n" ;
for ( Headers::const_iterator i = headers.begin() ; i != headers.end() ; ++i )
req << *i << '\n' ;
std::string data = "hahaha this is the new file!!!!!" ;
req << "Content-Length: " << data.size() << '\n'
<< "Content-Range: 0-" << data.size()-1 << '/' << data.size() << "\n\n\n"
<< data ;
std::string reqstr = req.str() ;
std::cout << "requesting: \n" << reqstr << std::endl ;
std::size_t iolen ;
if ( curl_easy_send(curl, &reqstr[0], reqstr.size(), &iolen) != CURLE_OK )
throw std::runtime_error( "cannot send" ) ;
while ( true )
{
char buf[1024+1] ;
FD_ZERO(&infd);
FD_ZERO(&outfd);
FD_ZERO(&errfd);
FD_SET(sockfd, &errfd); /* always check for error */
FD_SET(sockfd, &infd);
if ( select(sockfd + 1, &infd, &outfd, &errfd, &tv) == -1 )
throw std::runtime_error( "select fail" ) ;
if ( curl_easy_recv(curl, buf, 1024, &iolen) != CURLE_OK )
throw std::runtime_error( "cannot send" ) ;
buf[iolen] = '\0' ;
std::cout << "read: " << buf << std::endl ;
}
}
std::string Escape( const std::string& str )
{
CURL *curl = curl_easy_init();

View File

@ -57,8 +57,6 @@ namespace gr { namespace http
const std::string& data,
const Headers& hdr = Headers() ) ;
void Custom( const std::string& url, const std::string& host, const Headers& headers ) ;
std::string Escape( const std::string& str ) ;
std::string Unescape( const std::string& str ) ;