From: cantor Date: Tue, 28 Oct 2008 20:50:30 +0000 (+0000) Subject: https://bugs.internet2.edu/jira/browse/CPPXT-27 X-Git-Tag: 1.4.1~294 X-Git-Url: http://www.project-moonshot.org/gitweb/?a=commitdiff_plain;h=a6920551a9c01f78b57bdf5c4ca2d9563f29b063;hp=ecfe55519d549fcde2104e8d34cacb76a0892fd5;p=shibboleth%2Fxmltooling.git https://bugs.internet2.edu/jira/browse/CPPXT-27 git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/branches/REL_1@537 de75baf8-a10c-0410-a50a-987c0e22f00f --- diff --git a/.cproject b/.cproject index b78749e..895f74e 100644 --- a/.cproject +++ b/.cproject @@ -62,6 +62,7 @@ + @@ -76,6 +77,7 @@ + diff --git a/xmltooling/security/impl/SecurityHelper.cpp b/xmltooling/security/impl/SecurityHelper.cpp index 5c39bf8..a562bb0 100644 --- a/xmltooling/security/impl/SecurityHelper.cpp +++ b/xmltooling/security/impl/SecurityHelper.cpp @@ -344,13 +344,13 @@ vector::size_type SecurityHelper::loadCRLsFromFile( XSECCryptoKey* SecurityHelper::loadKeyFromURL(SOAPTransport& transport, const char* backing, const char* format, const char* password) { // Fetch the data. - istringstream dummy; - transport.send(dummy); + transport.send(); istream& msg = transport.receive(); // Dump to output file. ofstream out(backing, fstream::trunc|fstream::binary); out << msg.rdbuf(); + out.close(); return loadKeyFromFile(backing, format, password); } @@ -359,14 +359,13 @@ vector::size_type SecurityHelper::loadCertificatesFromURL( vector& certs, SOAPTransport& transport, const char* backing, const char* format, const char* password ) { - // Fetch the data. - istringstream dummy; - transport.send(dummy); + transport.send(); istream& msg = transport.receive(); // Dump to output file. ofstream out(backing, fstream::trunc|fstream::binary); out << msg.rdbuf(); + out.close(); return loadCertificatesFromFile(certs, backing, format, password); } @@ -376,13 +375,13 @@ vector::size_type SecurityHelper::loadCRLsFromURL( ) { // Fetch the data. - istringstream dummy; - transport.send(dummy); + transport.send(); istream& msg = transport.receive(); // Dump to output file. ofstream out(backing, fstream::trunc|fstream::binary); out << msg.rdbuf(); + out.close(); return loadCRLsFromFile(crls, backing, format); } diff --git a/xmltooling/soap/SOAPTransport.h b/xmltooling/soap/SOAPTransport.h index ec6ed9c..b2e7ef3 100644 --- a/xmltooling/soap/SOAPTransport.h +++ b/xmltooling/soap/SOAPTransport.h @@ -182,6 +182,17 @@ namespace xmltooling { virtual void send(std::istream& in)=0; /** + * Sends an optional stream of data over the transport. The function may return without + * having received any data, depending on the nature of the transport. + * + *

If the parameter is omitted, a request may be issued with no body if the transport + * supports that feature. + * + * @param in input stream to send + */ + virtual void send(std::istream* in=NULL); + + /** * Returns reference to response stream. The resulting stream must be * checked directly to determine whether data is available. * diff --git a/xmltooling/soap/impl/CURLSOAPTransport.cpp b/xmltooling/soap/impl/CURLSOAPTransport.cpp index 41828dc..5e0a656 100644 --- a/xmltooling/soap/impl/CURLSOAPTransport.cpp +++ b/xmltooling/soap/impl/CURLSOAPTransport.cpp @@ -166,7 +166,11 @@ namespace xmltooling { #endif } - void send(istream& in); + void send(istream& in) { + send(&in); + } + + void send(istream* in=NULL); istream& receive() { return m_stream; @@ -404,7 +408,7 @@ string CURLSOAPTransport::getContentType() const return content_type ? content_type : ""; } -void CURLSOAPTransport::send(istream& in) +void CURLSOAPTransport::send(istream* in) { #ifdef _DEBUG xmltooling::NDC ndc("send"); @@ -428,13 +432,13 @@ void CURLSOAPTransport::send(istream& in) curl_easy_setopt(m_handle,CURLOPT_POST,1); m_headers=curl_slist_append(m_headers,"Transfer-Encoding: chunked"); curl_easy_setopt(m_handle,CURLOPT_READFUNCTION,&curl_read_hook); - curl_easy_setopt(m_handle,CURLOPT_READDATA,&in); + curl_easy_setopt(m_handle,CURLOPT_READDATA,in); } else if (in) { char buf[1024]; - while (in) { - in.read(buf,1024); - msg.append(buf,in.gcount()); + while (*in) { + in->read(buf,1024); + msg.append(buf,in->gcount()); } curl_easy_setopt(m_handle,CURLOPT_POST,1); curl_easy_setopt(m_handle,CURLOPT_READFUNCTION,NULL); @@ -513,10 +517,10 @@ size_t xmltooling::curl_header_hook(void* ptr, size_t size, size_t nmemb, void* // callback to send data to server size_t xmltooling::curl_read_hook(void* ptr, size_t size, size_t nmemb, void* stream) { - // *stream is actually an istream object - istream& buf=*(reinterpret_cast(stream)); - buf.read(reinterpret_cast(ptr),size*nmemb); - return buf.gcount(); + // stream is actually an istream pointer + istream* buf=reinterpret_cast(stream); + buf->read(reinterpret_cast(ptr),size*nmemb); + return buf->gcount(); } // callback to buffer data from server diff --git a/xmltooling/soap/impl/SOAPClient.cpp b/xmltooling/soap/impl/SOAPClient.cpp index e89742b..7cf17f6 100644 --- a/xmltooling/soap/impl/SOAPClient.cpp +++ b/xmltooling/soap/impl/SOAPClient.cpp @@ -35,6 +35,13 @@ using namespace xmltooling::logging; using namespace xmltooling; using namespace std; +void SOAPTransport::send(istream* in) +{ + if (!in) + throw IOException("SOAP transport does not support an empty request body."); + return send(*in); +} + SOAPClient::~SOAPClient() { delete m_transport;