You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(622) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(303) |
Feb
(64) |
Mar
(5) |
Apr
(63) |
May
(82) |
Jun
(53) |
Jul
(50) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Christian P. <cp...@us...> - 2005-01-07 13:44:05
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5357/include/pclasses/Net Modified Files: Makefile.am Log Message: Added HTTPHeader.[h|cpp], HTTPClient.[h|cpp] Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.am 22 Dec 2004 17:54:40 -0000 1.1.1.1 +++ Makefile.am 7 Jan 2005 13:43:54 -0000 1.2 @@ -1,4 +1,4 @@ INCLUDES = METASOURCES = AUTO -pkginclude_HEADERS = NetworkAddress.h Socket.h InetAddress.h InetSocket.h +pkginclude_HEADERS = NetworkAddress.h Socket.h InetAddress.h InetSocket.h HTTPHeader.h HTTPClient.h |
From: Christian P. <cp...@us...> - 2005-01-07 13:44:03
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5357/src/Net Modified Files: Makefile.am Log Message: Added HTTPHeader.[h|cpp], HTTPClient.[h|cpp] Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/Makefile.am,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- Makefile.am 22 Dec 2004 17:54:35 -0000 1.1.1.1 +++ Makefile.am 7 Jan 2005 13:43:54 -0000 1.2 @@ -1,7 +1,8 @@ INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include $(all_includes) METASOURCES = AUTO lib_LTLIBRARIES = libpclasses_net.la -libpclasses_net_la_LIBADD = $(top_builddir)/src/libpclasses.la $(SOCKET_LIBS) +libpclasses_net_la_LIBADD = $(top_builddir)/src/libpclasses.la $(top_builddir)/src/IO/libpclasses_io.la \ + $(top_builddir)/src/System/libpclasses_system.la $(SOCKET_LIBS) libpclasses_net_la_SOURCES = Socket.cpp NetworkAddress.cpp InetAddress.cpp \ - InetSocket.cpp + InetSocket.cpp HTTPHeader.cpp HTTPClient.cpp noinst_HEADERS = SocketOption.h |
From: Christian P. <cp...@us...> - 2005-01-07 13:43:09
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5188/include/pclasses/IO Added Files: BZip2IOFilter.h Log Message: Added BZip2Filter.[h|cpp] --- NEW FILE: BZip2IOFilter.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_BZip2IOFilter_h #define P_IO_BZip2IOFilter_h #include <pclasses/IO/IOFilter.h> #include <pclasses/IO/BZip2.h> namespace P { namespace IO { //! BZip2 I/O Filter /*! bzlib2 stream based I/O Filter */ class BZip2IOFilter: public IOFilter { public: BZip2IOFilter(); ~BZip2IOFilter(); IOFilter* create(); void sync(bool close); bool isSeekable(); bool eof() const throw(); size_t read(char* buffer, size_t count) throw(IOError); size_t write(const char* buffer, size_t count) throw(IO::IOError); size_t peek(char* buffer, size_t count) throw(IOError); offset_t seek(offset_t offset, IO::IODevice::SeekMode mode) throw(IOError); offset_t size() const throw(IOError); private: void flushAvailBytes(); BZip2OutputStream* _strmOut; BZip2InputStream* _strmIn; }; } // !namespace IO } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-01-07 13:43:08
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5188/src/IO Added Files: BZip2IOFilter.cpp Log Message: Added BZip2Filter.[h|cpp] --- NEW FILE: BZip2IOFilter.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include <pclasses/IO/BZip2IOFilter.h> namespace P { namespace IO { BZip2IOFilter::BZip2IOFilter() : _strmOut(0), _strmIn(0) { } BZip2IOFilter::~BZip2IOFilter() { if(_strmOut) delete _strmOut; if(_strmIn) delete _strmIn; } IOFilter* BZip2IOFilter::create() { return new BZip2IOFilter(); } void BZip2IOFilter::sync(bool close) { // sync output stream ... if(_strmOut) { if(close) { while(!_strmOut->finish()) flushAvailBytes(); flushAvailBytes(); _strmOut->reset(); } else { _strmOut->sync(); flushAvailBytes(); } } if(_strmIn) { if(close) _strmIn->reset(); } IOFilter::sync(close); } bool BZip2IOFilter::isSeekable() { // seeking is too complex (for now ;-) return false; } bool BZip2IOFilter::eof() const throw() { if(_strmIn) return IOFilter::eof() && _strmIn->eof(); return IOFilter::eof(); } size_t BZip2IOFilter::read(char* buffer, size_t count) throw(IO::IOError) { if(!_strmIn) _strmIn = new P::IO::BZip2InputStream(); if(_strmIn->bytesAvail() < count) { // refill output buffer ... char tmp[1024]; size_t got = IOFilter::read(tmp, sizeof(tmp)); size_t consumed = _strmIn->decompress(tmp, got); if(consumed < sizeof(tmp)) { //@fixme: we need to buffer rememaining bytes we could not inflate } count = _strmIn->bytesAvail(); } // dequeue bytes available in output buffer ... memcpy(buffer, _strmIn->buffer(), count); _strmIn->dequeue(count); return count; } size_t BZip2IOFilter::write(const char* buffer, size_t count) throw(IO::IOError) { if(!_strmOut) _strmOut = new P::IO::BZip2OutputStream(9); size_t consumed = _strmOut->compress(buffer, count); flushAvailBytes(); return consumed; } size_t BZip2IOFilter::peek(char* buffer, size_t count) throw(IO::IOError) { return 0; } offset_t BZip2IOFilter::seek(offset_t offset, IO::IODevice::SeekMode mode) throw(IO::IOError) { throw IO::IOError(0, "Could not seek on device", P_SOURCEINFO); return -1; } offset_t BZip2IOFilter::size() const throw(IO::IOError) { //@fixme!!! return IOFilter::size(); } void BZip2IOFilter::flushAvailBytes() { size_t avail = _strmOut->bytesAvail(); if(avail) _strmOut->dequeue(IOFilter::write(_strmOut->buffer(), avail)); } } } |
From: Christian P. <cp...@us...> - 2005-01-07 13:41:34
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4968/include/pclasses/Net Added Files: HTTPClient.h HTTPHeader.h Log Message: Added HTTPHeader, HTTPRequestHeader, HTTPResponseHeader, HTTPRequest, HTTPResponse, HTTPClient. --- NEW FILE: HTTPHeader.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_Net_HTTPHeader_h #define P_Net_HTTPHeader_h #include <string> #include <map> namespace P { namespace Net { //! HTTP Header class /*! The base class for a HTTP-Request or -Response. */ class HTTPHeader { public: typedef std::map<std::string, std::string> FieldMap; typedef FieldMap::iterator iterator; typedef FieldMap::const_iterator const_iterator; HTTPHeader(); ~HTTPHeader(); void set(const std::string& head, const std::string& val); const std::string& get(const std::string& head) const; bool remove(const std::string& head); bool contains(const std::string& head) const; iterator find(const std::string& head); const_iterator find(const std::string& head) const; inline void setCacheControl(const std::string& val) { set("Cache-Control", val); } inline void setConnection(const std::string& val) { set("Connection", val); } inline const std::string& connection() const { return get("Connection"); } inline void setDate(const std::string& val) { set("Date", val); } inline void setPragma(const std::string& val) { set("Pragma", val); } inline void setTrailer(const std::string& val) { set("Trailer", val); } inline void setTransferEncoding(const std::string& val) { set("Transfer-Encoding", val); } inline const std::string& transferEncoding() const { return get("Transfer-Encoding"); } inline void setUpgrade(const std::string& val) { set("Upgrade", val); } inline void setVia(const std::string& val) { set("Via", val); } inline void setWarning(const std::string& val) { set("Warning", val); } const std::string& operator[](const std::string& head) const; inline const_iterator begin() const { return _values.begin(); } inline const_iterator end() const { return _values.end(); } inline iterator begin() { return _values.begin(); } inline iterator end() { return _values.end(); } private: FieldMap _values; }; //! HTTP Request-Header /*! A class used to store HTTP Request-Header informations */ class HTTPRequestHeader: public HTTPHeader { public: HTTPRequestHeader() {} ~HTTPRequestHeader() {} inline void setAccept(const std::string& val) { set("Accept", val); } inline void setAcceptCharset(const std::string& val) { set("Accept-Charset", val); } inline void setAcceptEncoding(const std::string& val) { set("Accept-Encoding", val); } inline void setAcceptLanguage(const std::string& val) { set("Accept-Language", val); } inline void setAuthorization(const std::string& val) { set("Authorization", val); } inline void setExpect(const std::string& val) { set("Expect", val); } inline void setFrom(const std::string& val) { set("From", val); } inline void setHost(const std::string& val) { set("Host", val); } inline void setIfMatch(const std::string& val) { set("If-Match", val); } inline void setIfModifiedSince(const std::string& val) { set("If-Modified-Since", val); } inline void setIfNoneMatch(const std::string& val) { set("If-None-Match", val); } inline void setIfRange(const std::string& val) { set("If-Range", val); } inline void setIfUnmodifiedSince(const std::string& val) { set("If-Unmodified-Since", val); } inline void setMaxForwards(const std::string& val) { set("Max-Forwards", val); } inline void setProxyAuthorization(const std::string& val) { set("Proxy-Authorization", val); } inline void setRange(const std::string& val) { set("Range", val); } inline void setReferer(const std::string& val) { set("Referer", val); } inline void setTE(const std::string& val) { set("TE", val); } inline void setUserAgent(const std::string& val) { set("User-Agent", val); } }; //! HTTP Response-Header /*! A class used to store HTTP Response-Header informations */ class HTTPResponseHeader: public HTTPHeader { public: HTTPResponseHeader() {} ~HTTPResponseHeader() {} inline void setAcceptRanges(const std::string& val) { set("Accept-Ranges", val); } inline void setAge(const std::string& val) { set("Age", val); } inline void setETag(const std::string& val) { set("ETag", val); } inline void setLocation(const std::string& val) { set("Location", val); } inline void setProxyAuthenticate(const std::string& val) { set("Proxy-Authenticate", val); } inline void setRetryAfter(const std::string& val) { set("Retry-After", val); } inline void setServer(const std::string& val) { set("Server", val); } inline void setVary(const std::string& val) { set("Vary", val); } inline void setWWWAuthenticate(const std::string& val) { set("WWW-Authenticate", val); } inline void setAllow(const std::string& val) { set("Allow", val); } inline void setContentEncoding(const std::string& val) { set("Content-Encoding", val); } inline void setContentLanguage(const std::string& val) { set("Content-Language", val); } inline void setContentLegth(const std::string& val) { set("Content-Legth", val); } inline void setContentLocation(const std::string& val) { set("Content-Location", val); } inline void setContentMD5(const std::string& val) { set("Content-MD5", val); } inline void setContentRange(const std::string& val) { set("Content-Range", val); } inline void setContentType(const std::string& val) { set("Content-Type", val); } inline void setExpires(const std::string& val) { set("Expires", val); } inline void setLastModified(const std::string& val) { set("Last-Modified", val); } }; } // !namespace Net } // !namespace P #endif --- NEW FILE: HTTPClient.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_Net_HTTPClient_h #define P_Net_HTTPClient_h #include <pclasses/IO/URL.h> #include <pclasses/Net/Socket.h> #include <pclasses/Net/HTTPHeader.h> namespace P { namespace Net { //! HTTP Request class HTTPRequest { public: //! HTTP Request methods enum Method { HEAD = 0, GET = 1, POST = 2, PUT = 3, DELETE = 4 }; HTTPRequest(Method method, const IO::URL& url); ~HTTPRequest(); Method method() const throw(); const IO::URL& url() const throw(); const HTTPRequestHeader& header() const throw(); HTTPRequestHeader& header() throw(); private: Method _method; IO::URL _url; HTTPRequestHeader _header; }; //! HTTP Response codes /*! Response codes used by the Hypertext-Transfer-Protocol. */ enum HTTPResponseCode { HTTP_100_CONTINUE = 100, HTTP_101_SWITCHING_PROTOCOL = 101, HTTP_200_OK = 200, HTTP_201_CREATED = 201, HTTP_202_ACCEPTED = 202, HTTP_203_NON_AUTH_INFO = 203, HTTP_204_NO_CONTENT = 204, HTTP_205_RESET_CONTENT = 205, HTTP_206_PARTIAL_CONTENT = 206, HTTP_300_MULTIPLE_CHOICES = 300, HTTP_301_MOVED_PERMANENTLY = 301, HTTP_302_FOUND = 302, HTTP_303_SEE_OTHER = 303, HTTP_304_NOT_MODIFIED = 304, HTTP_305_USE_PROXY = 305, HTTP_307_TEMPORARY_REDIRECT = 307, HTTP_400_BAD_REQUEST = 400, HTTP_401_UNAUTHORIZED = 401, HTTP_402_PAYMENT_REQUIRED = 402, HTTP_403_FORBIDDEN = 403, HTTP_404_NOT_FOUND = 404, HTTP_405_METHOD_NOT_ALLOWED = 405, HTTP_406_NOT_ACCEPTABLE = 406, HTTP_407_PROXY_AUTH_REQUIRED= 407, HTTP_408_REQUEST_TIMEOUT = 408, HTTP_409_CONFLICT = 409, HTTP_410_GONE = 410, HTTP_411_LENGTH_REQUIRED = 411, HTTP_412_PRECONDITION_FAILED= 412, HTTP_413_REQUEST_TOO_LARGE = 413, HTTP_414_REQ_URI_TOO_LONG = 414, HTTP_415_UNSUPP_MEDIA_TYPE = 415, HTTP_416_REQ_RANGE_INVALID = 416, HTTP_417_EXPECTATION_FAILED = 417, HTTP_500_INTERNAL_ERROR = 500, HTTP_501_NOT_IMPLEMENTED = 501, HTTP_502_BAD_GATEWAY = 502, HTTP_503_SERVICE_UNAVAILABLE= 503, HTTP_504_GATEWAY_TIMEOUT = 504, HTTP_505_VERSION_UNSUPPORTED= 505 }; class HTTPClient; class HTTPResponse: public IO::IODevice { public: HTTPResponse(HTTPClient& client, const std::string& proto, int code, const std::string& resp); ~HTTPResponse() throw(); const HTTPResponseHeader& header() const throw(); HTTPResponseHeader& header() throw(); const std::string& protocol() const throw(); int responseCode() const throw(); const std::string& response() const throw(); private: void _close() throw(IO::IOError); size_t _write(const char* buffer, size_t count) throw(IO::IOError); size_t _read(char* buffer, size_t count) throw(IO::IOError); HTTPClient* _client; HTTPResponseHeader _header; std::string _proto; int _responseCode; std::string _response; size_t _bytesRead; size_t _contentLength; bool _chunkedEncoding; }; class HTTPClient: public StreamSocket { public: HTTPClient(); HTTPClient(Domain d); HTTPClient(const NetworkAddress& addr, port_t port); ~HTTPClient() throw(); void open(Domain d) throw(IO::IOError); void sendRequest(HTTPRequest& req) throw(IO::IOError); HTTPResponse readResponse() throw(IO::IOError); }; } // !namespace Net } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-01-07 13:41:33
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4968/src/Net Added Files: HTTPClient.cpp HTTPHeader.cpp Log Message: Added HTTPHeader, HTTPRequestHeader, HTTPResponseHeader, HTTPRequest, HTTPResponse, HTTPClient. --- NEW FILE: HTTPHeader.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/Net/HTTPHeader.h" namespace P { namespace Net { HTTPHeader::HTTPHeader() { } HTTPHeader::~HTTPHeader() { } const std::string& HTTPHeader::get(const std::string& head) const { static std::string empty; const_iterator i = _values.find(head); if(i != _values.end()) return i->second; return empty; } void HTTPHeader::set(const std::string& head, const std::string& val) { _values[head] = val; } bool HTTPHeader::remove(const std::string& head) { iterator i = _values.find(head); if(i != _values.end()) { _values.erase(i); return true; } return false; } bool HTTPHeader::contains(const std::string& head) const { return (_values.find(head) != _values.end() ? true : false); } HTTPHeader::iterator HTTPHeader::find(const std::string& head) { return _values.find(head); } HTTPHeader::const_iterator HTTPHeader::find(const std::string& head) const { return _values.find(head); } const std::string& HTTPHeader::operator[](const std::string& head) const { return get(head); } } // !namespace Net } // !namespace P --- NEW FILE: HTTPClient.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/pclasses-config.h" #include "pclasses/IO/IOStream.h" #include "pclasses/Net/HTTPClient.h" #include <netinet/in.h> #ifdef PCLASSES_HAVE_APPLETALK # include <netatalk/at.h> #endif #ifdef PCLASSES_HAVE_IPX # include <netipx/ipx.h> #endif #include <sstream> namespace P { namespace Net { HTTPRequest::HTTPRequest(Method method, const IO::URL& url) : _method(method), _url(url) { } HTTPRequest::~HTTPRequest() { } HTTPRequest::Method HTTPRequest::method() const throw() { return _method; } const IO::URL& HTTPRequest::url() const throw() { return _url; } const HTTPRequestHeader& HTTPRequest::header() const throw() { return _header; } HTTPRequestHeader& HTTPRequest::header() throw() { return _header; } HTTPResponse::HTTPResponse(HTTPClient& client, const std::string& proto, int code, const std::string& resp) : _client(&client), _proto(proto), _responseCode(code), _response(resp), _bytesRead(0), _contentLength(0), _chunkedEncoding(false) { setAccess(Read); setValid(true); setEof(false); } HTTPResponse::~HTTPResponse() throw() { try { close(); } catch(...) { } } const HTTPResponseHeader& HTTPResponse::header() const throw() { return _header; } HTTPResponseHeader& HTTPResponse::header() throw() { return _header; } const std::string& HTTPResponse::protocol() const throw() { return _proto; } int HTTPResponse::responseCode() const throw() { return _responseCode; } const std::string& HTTPResponse::response() const throw() { return _response; } void HTTPResponse::_close() throw(IO::IOError) { setValid(false); setAccess(None); setEof(true); _client = 0; } size_t HTTPResponse::_write(const char* buffer, size_t count) throw(IO::IOError) { return 0; } size_t HTTPResponse::_read(char* buffer, size_t count) throw(IO::IOError) { if(!_bytesRead) { HTTPHeader::const_iterator i = _header.find("Content-Length"); if(i != _header.end()) { std::istringstream is(i->second); is >> _contentLength; } i = _header.find("Transfer-Encoding"); if(i != _header.end()) { if(i->second == "chunked") _chunkedEncoding = true; } } size_t ret; if(_chunkedEncoding) { // get next chunk size if it's unknown ... if(_contentLength == 0) { _readNextLine: std::string str = _client->readLine(); if(str.empty()) { setEof(true); return 0; } else if(str == "\r\n" || str == "\n") goto _readNextLine; std::istringstream is(str); is >> std::hex >> _contentLength; if(!_contentLength) { setEof(true); return 0; } } size_t bytesLeft = _contentLength - _bytesRead; if(count > bytesLeft) count = bytesLeft; ret = _client->read(buffer, count); if(!ret) setEof(true); _bytesRead += ret; // chunk finished ? if(_bytesRead == _contentLength) { _bytesRead = 0; _contentLength = 0; } } else { // we know the size of the response body ... if(_contentLength > 0) { if(_bytesRead == _contentLength) { setEof(true); return 0; } size_t bytesLeft = _contentLength - _bytesRead; if(count > bytesLeft) count = bytesLeft; ret = _client->read(buffer, count); _bytesRead += ret; if(!ret) setEof(true); } // we do not know the size of the response body ... // the connection will probably be closed after receiving // the body else { ret = _client->read(buffer, count); _bytesRead += ret; if(!ret) setEof(true); } } return ret; } HTTPClient::Domain AddrFamily2Domain(int family) { HTTPClient::Domain d; switch(family) { case AF_INET: d = Socket::Inet; break; case AF_INET6: d = Socket::Inet6; break; case AF_IPX: d = Socket::IPX; break; case AF_APPLETALK: d = Socket::AppleTalk; break; default: throw; } return d; } HTTPClient::HTTPClient() : StreamSocket() { } HTTPClient::HTTPClient(Domain d) : StreamSocket() { open(d); } HTTPClient::HTTPClient(const NetworkAddress& addr, port_t port) : StreamSocket() { open(AddrFamily2Domain(addr.family())); connect(addr, port); } HTTPClient::~HTTPClient() throw() { } void HTTPClient::open(Domain d) throw(IO::IOError) { Socket::open(d, Stream, 0); } void HTTPClient::sendRequest(HTTPRequest& req) throw(IO::IOError) { IO::IOStream reqs(*this); switch(req.method()) { case HTTPRequest::GET: reqs << "GET "; break; case HTTPRequest::HEAD: reqs << "HEAD "; break; case HTTPRequest::POST: reqs << "POST "; break; case HTTPRequest::PUT: reqs << "PUT "; break; case HTTPRequest::DELETE: reqs << "DELETE "; break; default: throw RuntimeError("HTTP request not implemented",P_SOURCEINFO); } // send request line .. reqs << req.url().path() << " HTTP/1.1\r\n"; // send header lines ... HTTPHeader::const_iterator i = req.header().begin(); bool hostFound = false; while(i != req.header().end()) { if(i->first == "Host") hostFound = true; reqs << i->first << ": " << i->second << "\r\n"; ++i; } // "Host:" header is required in HTTP/1.1! if(!hostFound) reqs << "Host: " << req.url().host() << "\r\n"; // terminate request and flush stream reqs << "\r\n"; reqs.sync(); } HTTPResponse HTTPClient::readResponse() throw(IO::IOError) { std::string line1 = readLine(); std::string httpProto, httpResponse; int httpResponseCode; std::string tmp; std::istringstream is(line1); is >> httpProto; is >> httpResponseCode; //is >> tmp; httpCode = atoi(tmp.c_str()); is >> httpResponse; HTTPResponse resp(*this, httpProto, httpResponseCode, httpResponse); while(1) { tmp = readLine(); // response header terminated ? if(tmp == "\r\n" || tmp == "\n") break; size_t pos = tmp.find(':'); if(pos != std::string::npos && tmp.size() > 4) { std::string headName = tmp.substr(0, pos); std::string headVal = tmp.substr(pos+2, tmp.size()-(pos+4)); std::cerr << headName << '=' << headVal << std::endl; resp.header().set(headName, headVal); } } return resp; } } // !namespace Net } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-07 13:40:39
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4806/src/Net Modified Files: InetAddress.cpp Log Message: Added InetAddress::fromString(). Fixed InetAddress string ctor and assign operator. Index: InetAddress.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/InetAddress.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- InetAddress.cpp 23 Dec 2004 06:23:09 -0000 1.3 +++ InetAddress.cpp 7 Jan 2005 13:40:30 -0000 1.4 @@ -18,8 +18,11 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "pclasses/System/CriticalSection.h" #include "pclasses/Net/InetAddress.h" + #include <netinet/in.h> +#include <arpa/inet.h> namespace P { @@ -42,6 +45,12 @@ { } +InetAddress::InetAddress(const std::string& str) +: NetworkAddress(AF_INET, 0, sizeof(in_addr)) +{ + *this = fromString(str); +} + InetAddress::~InetAddress() { } @@ -61,11 +70,14 @@ return (*this == InetAddress(Loopback)); } -Unicode::String InetAddress::str() const +std::string InetAddress::str() const { - //@todo InetAddress::str() - return Unicode::String(); - // ^^^^ added by stephan to avoid an implicit return warning. + // inet_ntoa is not reentrant on many systems ... + static System::CriticalSection cs; + System::CriticalSection::ScopedLock lck(cs); + + std::string ret = inet_ntoa(*((in_addr*)addr())); + return ret; } InetAddress* InetAddress::clone() const @@ -91,6 +103,18 @@ return *this; } +InetAddress& InetAddress::operator=(const std::string& str) +{ + *this = fromString(str); + return *this; +} + +InetAddress InetAddress::fromString(const std::string& str) +{ + in_addr addr; + inet_aton(str.c_str(), &addr); + return InetAddress(addr); +} } |
From: Christian P. <cp...@us...> - 2005-01-07 13:40:39
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4806/include/pclasses/Net Modified Files: InetAddress.h Log Message: Added InetAddress::fromString(). Fixed InetAddress string ctor and assign operator. Index: InetAddress.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/InetAddress.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- InetAddress.h 23 Dec 2004 04:32:16 -0000 1.2 +++ InetAddress.h 7 Jan 2005 13:40:30 -0000 1.3 @@ -29,7 +29,6 @@ namespace Net { - class InetAddress: public NetworkAddress { public: enum Special { @@ -38,21 +37,25 @@ Loopback = 0x7f000001 }; - InetAddress(uint32_t addr); + InetAddress(uint32_t addr = Any); InetAddress(const in_addr& addr); InetAddress(const NetworkAddress& addr); + InetAddress(const std::string& addr); ~InetAddress(); bool isAny() const throw(); bool isBroadcast() const throw(); bool isLoopback() const throw(); - Unicode::String str() const; + std::string str() const; InetAddress* clone() const; InetAddress& operator=(uint32_t addr); InetAddress& operator=(const in_addr& addr); InetAddress& operator=(const NetworkAddress& addr); + InetAddress& operator=(const std::string& str); + + static InetAddress fromString(const std::string& str); }; |
From: Christian P. <cp...@us...> - 2005-01-07 13:39:11
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4490/include/pclasses/Net Modified Files: Socket.h Log Message: Added Socket::connect(). Index: Socket.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/Socket.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- Socket.h 3 Jan 2005 13:50:44 -0000 1.3 +++ Socket.h 7 Jan 2005 13:39:03 -0000 1.4 @@ -67,6 +67,8 @@ //! Bind socket to given address and port void bind(const NetworkAddress& addr, port_t port) throw(IO::IOError); + void connect(const NetworkAddress& addr, port_t port) throw(IO::IOError); + void setSendTimeout(unsigned int timeout) throw(IO::IOError); unsigned int sendTimeout() const throw(IO::IOError); |
From: Christian P. <cp...@us...> - 2005-01-07 13:39:11
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4490/src/Net Modified Files: Socket.cpp Log Message: Added Socket::connect(). Index: Socket.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/Socket.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Socket.cpp 3 Jan 2005 13:50:45 -0000 1.4 +++ Socket.cpp 7 Jan 2005 13:39:02 -0000 1.5 @@ -31,11 +31,11 @@ #include <netinet/in.h> -#ifdef HAVE_APPLETALK +#ifdef PCLASSES_HAVE_APPLETALK # include <netatalk/at.h> #endif -#ifdef HAVE_IPX +#ifdef PCLASSES_HAVE_IPX # include <netipx/ipx.h> #endif @@ -341,6 +341,18 @@ throw IO::IOError(errno, "Could not bind address to socket", P_SOURCEINFO); } +void Socket::connect(const NetworkAddress& addr, port_t port) throw(IO::IOError) +{ + size_t socketAddrLen = 0; + sockaddr* socketAddr = makeSocketAddress(addr, port, socketAddrLen); + + int ret = ::connect(_handle, socketAddr, socketAddrLen); + delete socketAddr; + + if(ret == -1) + throw IO::IOError(errno, "Could not connect socket", P_SOURCEINFO); +} + void Socket::setSendTimeout(unsigned int timeout) throw(IO::IOError) { SocketOption<SOL_SOCKET, SO_SNDTIMEO, int> opt(_handle); |
From: Christian P. <cp...@us...> - 2005-01-07 13:38:31
|
Update of /cvsroot/pclasses/pclasses2/src/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4303/src/Net Modified Files: NetworkAddress.cpp Log Message: Changed return-type of NetworkAddress::str() from Unicode::String to std::string. Fixed bug in addr-family ctor of NetworkAddress. Index: NetworkAddress.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/Net/NetworkAddress.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- NetworkAddress.cpp 22 Dec 2004 17:54:34 -0000 1.1.1.1 +++ NetworkAddress.cpp 7 Jan 2005 13:38:15 -0000 1.2 @@ -34,7 +34,7 @@ NetworkAddress::NetworkAddress(int family, const void* addr, size_t addrLen) : _family(family), _addr((void*)new char[addrLen]), _addrLen(addrLen) { - if(_addr) + if(addr) memcpy(_addr, addr, _addrLen); else memset(_addr, 0, _addrLen); |
From: Christian P. <cp...@us...> - 2005-01-07 13:38:31
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/Net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4303/include/pclasses/Net Modified Files: NetworkAddress.h Log Message: Changed return-type of NetworkAddress::str() from Unicode::String to std::string. Fixed bug in addr-family ctor of NetworkAddress. Index: NetworkAddress.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/Net/NetworkAddress.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- NetworkAddress.h 23 Dec 2004 04:32:16 -0000 1.2 +++ NetworkAddress.h 7 Jan 2005 13:38:22 -0000 1.3 @@ -22,7 +22,7 @@ #define P_Net_NetworkAddress_h #include <pclasses/BasicTypes.h> -#include <pclasses/Unicode/String.h> +#include <string> namespace P { @@ -41,7 +41,7 @@ size_t addrLen() const throw(); - virtual Unicode::String str() const = 0; + virtual std::string str() const = 0; virtual NetworkAddress* clone() const = 0; |
From: Christian P. <cp...@us...> - 2005-01-07 13:33:28
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3043/src/IO Modified Files: IODevice.cpp Log Message: Added IODevice::readLine() Index: IODevice.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IODevice.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- IODevice.cpp 6 Jan 2005 17:24:20 -0000 1.6 +++ IODevice.cpp 7 Jan 2005 13:33:15 -0000 1.7 @@ -20,19 +20,21 @@ #include "pclasses/IO/IODevice.h" #include "pclasses/IO/IOFilter.h" +#include <sstream> namespace P { namespace IO { IODevice::IODevice() throw() -: _filter(0), _filterOwner(false), _valid(false), _access(None), _eof(true) +: _filter(0), _filterOwner(false), _valid(false), _access(None), _eof(true), + _readBuffer(0), _readBuffCount(0) { } IODevice::IODevice(const IODevice& dev) throw() : _filter(0), _filterOwner(false), _valid(dev._valid), _access(dev._access), - _eof(dev._eof) + _eof(dev._eof), _readBuffer(0), _readBuffCount(0) { if(dev._filter) { @@ -46,12 +48,17 @@ { if(_filterOwner) delete _filter; + + if(_readBuffer) + delete[] _readBuffer; } void IODevice::close() throw(IOError) { if(valid()) { + _readBuffCount = 0; + if(_filter) _filter->sync(true); @@ -61,7 +68,68 @@ size_t IODevice::read(char* buffer, size_t count) throw(IOError) { - return _filter ? _filter->read(buffer, count) : _read(buffer, count); + size_t offset = 0; + + // deliver buffered bytes first ... + if(_readBuffer && _readBuffCount) + { + size_t n = _readBuffCount > count ? count : _readBuffCount; + memcpy(buffer, _readBuffNext, n); + _readBuffCount -= n; + _readBuffNext += n; + offset = n; + count -= n; + if(!count) + return n; + } + + return _filter ? + (_filter->read(buffer + offset, count) + offset) + : (_read(buffer + offset, count) + offset); +} + +std::string IODevice::readLine() throw(IOError) +{ + // alloce read buffer if we have'nt done it yet ... + if(!_readBuffer) + { + _readBuffer = new char[1024]; + _readBuffSize = 1024; + _readBuffCount = 0; + _readBuffNext = 0; + } + + std::ostringstream ret; + + // read data until newline ... + bool finished = false; + while(!finished) + { + // buffer is empty, read some more ... + if(!_readBuffCount) + { + size_t bytesRead = read(_readBuffer, _readBuffSize); + if(!bytesRead) + break; + + _readBuffCount = bytesRead; + _readBuffNext = _readBuffer; + } + + // search for newline ... + for(size_t i = 0; i < _readBuffCount; i++) + { + ret << *_readBuffNext; + --_readBuffCount; + if(*_readBuffNext++ == '\n') + { + finished = true; + break; + } + } + } + + return ret.str(); } size_t IODevice::write(const char* buffer, size_t count) throw(IOError) @@ -215,6 +283,7 @@ _valid = dev._valid; _access = dev._access; _eof = dev._eof; + _readBuffCount = 0; return *this; } |
From: Christian P. <cp...@us...> - 2005-01-07 13:33:28
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3043/include/pclasses/IO Modified Files: IODevice.h Log Message: Added IODevice::readLine() Index: IODevice.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/IODevice.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- IODevice.h 3 Jan 2005 13:50:44 -0000 1.4 +++ IODevice.h 7 Jan 2005 13:33:15 -0000 1.5 @@ -70,6 +70,8 @@ size_t read(char* buffer, size_t count) throw(IOError); + std::string readLine() throw(IOError); + size_t write(const char* buffer, size_t count) throw(IOError); @@ -129,6 +131,11 @@ bool _valid; AccessMode _access; bool _eof; + /* we need to buffer data if readLine() was used */ + char* _readBuffer; + size_t _readBuffSize; + size_t _readBuffCount; + char* _readBuffNext; }; class IOListener { |
From: Christian P. <cp...@us...> - 2005-01-06 19:32:16
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20723 Modified Files: IOTest.cpp Log Message: Added test for BZip2IOFilter Index: IOTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/IOTest.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- IOTest.cpp 6 Jan 2005 17:02:00 -0000 1.3 +++ IOTest.cpp 6 Jan 2005 19:32:06 -0000 1.4 @@ -22,6 +22,7 @@ #include "pclasses/IO/IOStream.h" #include "pclasses/IO/IOFilter.h" #include "pclasses/IO/ZLibIOFilter.h" +#include "pclasses/IO/BZip2IOFilter.h" #include "pclasses/System/File.h" #include "pclasses/System/Pipe.h" #include "pclasses/System/Process.h" @@ -51,6 +52,14 @@ { char data[] = "test"; + try + { + File::unlink("pclasses_file_test.tmp"); + } + catch(...) + { + } + File file("pclasses_file_test.tmp", File::ReadWrite); file.setFilter(_filter); P_TEST(file.valid()); @@ -70,6 +79,8 @@ file.open("pclasses_file_test.tmp", File::Read); } + P_TEST(!file.eof()); + // read data from file char tmp[4]; P_TEST(file.read(tmp, 4) == 4); @@ -212,7 +223,13 @@ P::ProcessIOTest piot2(new P::IO::IOFilter()); piot2.run(); + std::cerr << "Testing zlib stream..." << std::endl; P::FileTest ft3(new P::IO::ZLibIOFilter()); ft3.run(); + + std::cerr << "Testing bzip2 stream..." << std::endl; + P::FileTest ft4(new P::IO::BZip2IOFilter()); + ft4.run(); + return 0; } |
From: Christian P. <cp...@us...> - 2005-01-06 19:26:42
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19240/include/pclasses/IO Modified Files: Makefile.am Log Message: Added BZip2IOFilter.h Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Makefile.am 6 Jan 2005 18:31:40 -0000 1.5 +++ Makefile.am 6 Jan 2005 19:26:30 -0000 1.6 @@ -1,3 +1,3 @@ INCLUDES = METASOURCES = AUTO -pkginclude_HEADERS = IOError.h IODevice.h IOStream.h IOFilter.h URL.h ZLib.h ZLibIOFilter.h BZip2.h +pkginclude_HEADERS = IOError.h IODevice.h IOStream.h IOFilter.h URL.h ZLib.h ZLibIOFilter.h BZip2.h BZip2IOFilter.h |
From: Christian P. <cp...@us...> - 2005-01-06 19:23:22
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18649/src/IO Modified Files: ZLibIOFilter.cpp Log Message: Fixed ZLibInputStream::eof() Index: ZLibIOFilter.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/ZLibIOFilter.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ZLibIOFilter.cpp 6 Jan 2005 17:24:22 -0000 1.2 +++ ZLibIOFilter.cpp 6 Jan 2005 19:23:13 -0000 1.3 @@ -80,7 +80,10 @@ bool ZLibIOFilter::eof() const throw() { - return _strmIn ? _strmIn->eof() : false; + if(_strmIn) + return IOFilter::eof() && _strmIn->eof(); + + return IOFilter::eof(); } size_t ZLibIOFilter::read(char* buffer, size_t count) throw(IO::IOError) |
From: Christian P. <cp...@us...> - 2005-01-06 19:22:39
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18331/src/IO Modified Files: ZLib.cpp BZip2.cpp Makefile.am Log Message: Fixed [ZLib|BZip2]OutputStream: only finish when we have compressed something Index: ZLib.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/ZLib.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- ZLib.cpp 6 Jan 2005 17:24:22 -0000 1.3 +++ ZLib.cpp 6 Jan 2005 19:22:24 -0000 1.4 @@ -150,13 +150,16 @@ bool ZLibOutputStream::finish() throw(ZLibError) { - int ret = ::deflate(_strm, Z_FINISH); - // not enough buffer was avail... should call finish() again - if(ret == Z_OK) - return false; - - if(ret != Z_STREAM_END) - throw ZLibError(Z_BUF_ERROR, 0, "Could not finish stream", P_SOURCEINFO); + if(_strm->total_in > 0) + { + int ret = ::deflate(_strm, Z_FINISH); + // not enough buffer was avail... should call finish() again + if(ret == Z_OK) + return false; + + if(ret != Z_STREAM_END) + throw ZLibError(Z_BUF_ERROR, 0, "Could not finish stream", P_SOURCEINFO); + } return true; } Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- Makefile.am 6 Jan 2005 18:30:33 -0000 1.5 +++ Makefile.am 6 Jan 2005 19:22:24 -0000 1.6 @@ -2,5 +2,5 @@ METASOURCES = AUTO lib_LTLIBRARIES = libpclasses_io.la -libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp BZip2.cpp +libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp BZip2.cpp BZip2IOFilter.cpp libpclasses_io_la_LIBADD = $(top_builddir)/src/libpclasses.la -lz -lbz2 Index: BZip2.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/BZip2.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- BZip2.cpp 6 Jan 2005 18:30:33 -0000 1.1 +++ BZip2.cpp 6 Jan 2005 19:22:24 -0000 1.2 @@ -130,7 +130,7 @@ ((bz_stream*)_strm)->avail_in = count; int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_RUN); - if(ret != BZ_OK) + if(ret != BZ_RUN_OK) throw BZip2Error(ret, "Could not compress", P_SOURCEINFO); // return with number of bytes consumed ... @@ -141,19 +141,22 @@ void BZip2OutputStream::sync() throw(BZip2Error) { int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_FLUSH); - if(ret != BZ_OK) + if(ret != BZ_FLUSH_OK) throw BZip2Error(ret, "Could not flush stream", P_SOURCEINFO); } bool BZip2OutputStream::finish() throw(BZip2Error) { - int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_FINISH); - // not enough buffer was avail... should call finish() again - if(ret == BZ_FINISH_OK) - return false; - - if(ret != BZ_STREAM_END) - throw BZip2Error(BZ_OUTBUFF_FULL, "Could not finish stream", P_SOURCEINFO); + if(((bz_stream*)_strm)->total_in_lo32 > 0) + { + int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_FINISH); + // not enough buffer was avail... should call finish() again + if(ret == BZ_FINISH_OK) + return false; + + if(ret != BZ_STREAM_END) + throw BZip2Error(BZ_OUTBUFF_FULL, "Could not finish stream", P_SOURCEINFO); + } return true; } @@ -162,6 +165,10 @@ { ((bz_stream*)_strm)->next_out = _buffer; ((bz_stream*)_strm)->avail_out = _bufferSize; + ((bz_stream*)_strm)->total_in_lo32 = 0; + ((bz_stream*)_strm)->total_in_hi32 = 0; + ((bz_stream*)_strm)->total_out_lo32 = 0; + ((bz_stream*)_strm)->total_out_hi32 = 0; } BZip2InputStream::BZip2InputStream(size_t bufferSize) throw(BZip2Error) |
From: Christian P. <cp...@us...> - 2005-01-06 18:31:50
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6589/include/pclasses/IO Modified Files: Makefile.am Log Message: Added BZip2.h Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Makefile.am 6 Jan 2005 16:53:44 -0000 1.4 +++ Makefile.am 6 Jan 2005 18:31:40 -0000 1.5 @@ -1,3 +1,3 @@ INCLUDES = METASOURCES = AUTO -pkginclude_HEADERS = IOError.h IODevice.h IOStream.h IOFilter.h URL.h ZLib.h ZLibIOFilter.h +pkginclude_HEADERS = IOError.h IODevice.h IOStream.h IOFilter.h URL.h ZLib.h ZLibIOFilter.h BZip2.h |
From: Christian P. <cp...@us...> - 2005-01-06 18:30:42
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6341/include/pclasses/IO Added Files: BZip2.h Log Message: Added bzip2 support. --- NEW FILE: BZip2.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_BZip2_h #define P_IO_BZip2_h #include <pclasses/Exception.h> #include <pclasses/IntTypes.h> #include <string> namespace P { namespace IO { //! BZip2 error class BZip2Error: public RuntimeError { public: BZip2Error(int err, const char* what, const SourceInfo& si); ~BZip2Error(); int errorNo() const throw(); std::string msg() const throw(); private: int _err; }; //! Bzip2 stream base class BZip2Stream { public: BZip2Stream(size_t bufferSize); virtual ~BZip2Stream(); //! Number of bytes available to consume size_t bytesAvail() const throw(); //! Returns a pointer to the produced data const char* buffer() const throw(); //! Dequeue produced data size_t dequeue(size_t count) throw(BZip2Error); //! Put data into producer buffer void put(const char* buffer, size_t count) throw(BZip2Error); protected: void* _strm; char* _buffer; size_t _bufferSize; }; //! BZip2 output (deflate) stream class BZip2OutputStream: public BZip2Stream { public: BZip2OutputStream(int level = 6, size_t bufferSize = 1024) throw(BZip2Error); ~BZip2OutputStream() throw(); //! Compress buffer into output buffer /*! Returns the number of bytes actually deflated. */ size_t compress(const char* buffer, size_t count) throw(BZip2Error); void sync() throw(BZip2Error); //! Finish compression and reset state bool finish() throw(BZip2Error); //! Reset stream void reset() throw(BZip2Error); }; //! BZip2 input (inflate) stream class BZip2InputStream: public BZip2Stream { public: BZip2InputStream(size_t bufferSize = 1024) throw(BZip2Error); ~BZip2InputStream() throw(); //! Decompress buffer into output buffer /*! Returns the number of bytes actually inflated, which may be NULL when <count> is NULL or the end of the stream has been reached. */ size_t decompress(const char* buffer, size_t count) throw(BZip2Error); bool eof() const throw(); //! Reset stream void reset() throw(BZip2Error); private: bool _eof; }; } // !namespace IO } // !namespace P #endif |
From: Christian P. <cp...@us...> - 2005-01-06 18:30:42
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6341/src/IO Modified Files: Makefile.am Added Files: BZip2.cpp Log Message: Added bzip2 support. Index: Makefile.am =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Makefile.am 6 Jan 2005 16:53:44 -0000 1.4 +++ Makefile.am 6 Jan 2005 18:30:33 -0000 1.5 @@ -2,5 +2,5 @@ METASOURCES = AUTO lib_LTLIBRARIES = libpclasses_io.la -libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp -libpclasses_io_la_LIBADD = $(top_builddir)/src/libpclasses.la -lz +libpclasses_io_la_SOURCES = IOError.cpp IODevice.cpp IOStream.cpp IOFilter.cpp URL.cpp ZLib.cpp ZLibIOFilter.cpp BZip2.cpp +libpclasses_io_la_LIBADD = $(top_builddir)/src/libpclasses.la -lz -lbz2 --- NEW FILE: BZip2.cpp --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #include "pclasses/IO/BZip2.h" #include <bzlib.h> namespace P { namespace IO { BZip2Error::BZip2Error(int err, const char* what, const SourceInfo& si) : RuntimeError(what, si), _err(err) { } BZip2Error::~BZip2Error() { } int BZip2Error::errorNo() const throw() { return _err; } std::string BZip2Error::msg() const throw() { return ""; } BZip2Stream::BZip2Stream(size_t bufferSize) { if(bufferSize < 1) bufferSize = 64; bz_stream* strm = new bz_stream; _buffer = new char[bufferSize]; _bufferSize = bufferSize; strm->bzalloc = 0; strm->bzfree = 0; strm->opaque = 0; strm->next_in = 0; strm->next_out = _buffer; strm->avail_in = 0; strm->avail_out = _bufferSize; _strm = (void*)strm; } BZip2Stream::~BZip2Stream() { delete ((bz_stream*)_strm); delete[] _buffer; } size_t BZip2Stream::bytesAvail() const throw() { return _bufferSize - ((bz_stream*)_strm)->avail_out; } const char* BZip2Stream::buffer() const throw() { return (const char*)((bz_stream*)_strm)->next_out - (_bufferSize - ((bz_stream*)_strm)->avail_out); } size_t BZip2Stream::dequeue(size_t count) throw(BZip2Error) { size_t avail = bytesAvail(); if(count > avail) count = avail; // move remaining bytes to top of buffer ... if(count < avail) memmove(_buffer, ((bz_stream*)_strm)->next_out - avail + count, avail - count); ((bz_stream*)_strm)->next_out -= count; ((bz_stream*)_strm)->avail_out += count; return count; } void BZip2Stream::put(const char* buffer, size_t count) throw(BZip2Error) { if(((bz_stream*)_strm)->avail_out < count) throw BZip2Error(BZ_OUTBUFF_FULL, "Could not put data into output buffer", P_SOURCEINFO); memcpy(((bz_stream*)_strm)->next_out, buffer, count); ((bz_stream*)_strm)->next_out += count; ((bz_stream*)_strm)->avail_out -= count; } BZip2OutputStream::BZip2OutputStream(int level, size_t bufferSize) throw(BZip2Error) : BZip2Stream(bufferSize) { int ret; if((ret = ::BZ2_bzCompressInit((bz_stream*)_strm, 9, 0, 30)) != BZ_OK) throw BZip2Error(ret, "Could not init bzlib compression", P_SOURCEINFO); } BZip2OutputStream::~BZip2OutputStream() throw() { ::BZ2_bzCompressEnd((bz_stream*)_strm); } size_t BZip2OutputStream::compress(const char* buffer, size_t count) throw(BZip2Error) { if(!count) return 0; ((bz_stream*)_strm)->next_in = (char*)buffer; ((bz_stream*)_strm)->avail_in = count; int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_RUN); if(ret != BZ_OK) throw BZip2Error(ret, "Could not compress", P_SOURCEINFO); // return with number of bytes consumed ... size_t deflated = count - ((bz_stream*)_strm)->avail_in; return deflated; } void BZip2OutputStream::sync() throw(BZip2Error) { int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_FLUSH); if(ret != BZ_OK) throw BZip2Error(ret, "Could not flush stream", P_SOURCEINFO); } bool BZip2OutputStream::finish() throw(BZip2Error) { int ret = ::BZ2_bzCompress((bz_stream*)_strm, BZ_FINISH); // not enough buffer was avail... should call finish() again if(ret == BZ_FINISH_OK) return false; if(ret != BZ_STREAM_END) throw BZip2Error(BZ_OUTBUFF_FULL, "Could not finish stream", P_SOURCEINFO); return true; } void BZip2OutputStream::reset() throw(BZip2Error) { ((bz_stream*)_strm)->next_out = _buffer; ((bz_stream*)_strm)->avail_out = _bufferSize; } BZip2InputStream::BZip2InputStream(size_t bufferSize) throw(BZip2Error) : BZip2Stream(bufferSize), _eof(false) { int ret; if((ret = ::BZ2_bzDecompressInit((bz_stream*)_strm, 0, 0)) != BZ_OK) throw BZip2Error(ret, "Could not init bzlib decompression", P_SOURCEINFO); } BZip2InputStream::~BZip2InputStream() throw() { ::BZ2_bzDecompressEnd((bz_stream*)_strm); } size_t BZip2InputStream::decompress(const char* buffer, size_t count) throw(BZip2Error) { if(!count) return 0; ((bz_stream*)_strm)->next_in = (char*)buffer; ((bz_stream*)_strm)->avail_in = count; int ret = ::BZ2_bzDecompress((bz_stream*)_strm); if(ret == BZ_STREAM_END) { // we do nothing, so this or next call to inflate() returns 0 _eof = true; } else if(ret != BZ_OK) throw BZip2Error(ret, "Could not decompress", P_SOURCEINFO); // return with number of bytes consumed ... size_t inflated = count - ((bz_stream*)_strm)->avail_in; return inflated; } bool BZip2InputStream::eof() const throw() { return _eof; } void BZip2InputStream::reset() throw(BZip2Error) { ((bz_stream*)_strm)->next_out = _buffer; ((bz_stream*)_strm)->avail_out = _bufferSize; _eof = false; } } // !namespace IO } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-06 17:24:33
|
Update of /cvsroot/pclasses/pclasses2/src/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22206/src/IO Modified Files: IODevice.cpp IOFilter.cpp ZLib.cpp ZLibIOFilter.cpp Log Message: Fix for IODevice::eof() - must be also proxied through the filter. Index: ZLib.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/ZLib.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ZLib.cpp 6 Jan 2005 16:41:38 -0000 1.2 +++ ZLib.cpp 6 Jan 2005 17:24:22 -0000 1.3 @@ -172,7 +172,7 @@ } ZLibInputStream::ZLibInputStream(size_t bufferSize) throw(ZLibError) -: ZLibStream(bufferSize) +: ZLibStream(bufferSize), _eof(false) { int ret; if((ret = ::inflateInit(_strm)) != Z_OK) @@ -195,7 +195,8 @@ int ret = ::inflate(_strm, Z_NO_FLUSH); if(ret == Z_STREAM_END) { - // we do nothing, so this or next call to inflate() returns 0 + // we do nothing, so this or next call to inflate() returns 0 + _eof = true; } else if(ret != Z_OK) throw ZLibError(ret, _strm->msg, "Could not inflate", P_SOURCEINFO); @@ -205,10 +206,16 @@ return inflated; } +bool ZLibInputStream::eof() const throw() +{ + return _eof; +} + void ZLibInputStream::reset() throw(ZLibError) { _strm->next_out = (Bytef*)_buffer; _strm->avail_out = _bufferSize; + _eof = false; int ret = ::inflateReset(_strm); if(ret != Z_OK) Index: IODevice.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IODevice.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- IODevice.cpp 6 Jan 2005 16:40:14 -0000 1.5 +++ IODevice.cpp 6 Jan 2005 17:24:20 -0000 1.6 @@ -165,7 +165,7 @@ bool IODevice::eof() const throw() { - return _eof; + return _filter ? _filter->eof() : _eof; } void IODevice::setValid(bool v) throw() Index: ZLibIOFilter.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/ZLibIOFilter.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ZLibIOFilter.cpp 6 Jan 2005 16:47:47 -0000 1.1 +++ ZLibIOFilter.cpp 6 Jan 2005 17:24:22 -0000 1.2 @@ -78,6 +78,11 @@ return false; } +bool ZLibIOFilter::eof() const throw() +{ + return _strmIn ? _strmIn->eof() : false; +} + size_t ZLibIOFilter::read(char* buffer, size_t count) throw(IO::IOError) { if(!_strmIn) Index: IOFilter.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/IO/IOFilter.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- IOFilter.cpp 6 Jan 2005 16:40:14 -0000 1.2 +++ IOFilter.cpp 6 Jan 2005 17:24:22 -0000 1.3 @@ -59,6 +59,11 @@ return _dev->_isSeekable(); } +bool IOFilter::eof() const throw() +{ + return _dev->_eof; +} + size_t IOFilter::read(char* buffer, size_t count) throw(IO::IOError) { return _dev->_read(buffer, count); |
From: Christian P. <cp...@us...> - 2005-01-06 17:24:29
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22206/include/pclasses/IO Modified Files: IOFilter.h ZLib.h ZLibIOFilter.h Log Message: Fix for IODevice::eof() - must be also proxied through the filter. Index: ZLibIOFilter.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/ZLibIOFilter.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- ZLibIOFilter.h 6 Jan 2005 16:47:47 -0000 1.1 +++ ZLibIOFilter.h 6 Jan 2005 17:24:20 -0000 1.2 @@ -43,6 +43,8 @@ bool isSeekable(); + bool eof() const throw(); + size_t read(char* buffer, size_t count) throw(IOError); size_t write(const char* buffer, size_t count) Index: IOFilter.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/IOFilter.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- IOFilter.h 6 Jan 2005 16:40:14 -0000 1.2 +++ IOFilter.h 6 Jan 2005 17:24:20 -0000 1.3 @@ -41,6 +41,8 @@ virtual bool isSeekable(); + virtual bool eof() const throw(); + virtual size_t read(char* buffer, size_t count) throw(IOError); virtual size_t write(const char* buffer, size_t count) Index: ZLib.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/IO/ZLib.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- ZLib.h 6 Jan 2005 16:41:38 -0000 1.2 +++ ZLib.h 6 Jan 2005 17:24:20 -0000 1.3 @@ -107,8 +107,13 @@ */ size_t inflate(const char* buffer, size_t count) throw(ZLibError); + bool eof() const throw(); + //! Reset stream void reset() throw(ZLibError); + + private: + bool _eof; }; } // !namespace IO |
From: Christian P. <cp...@us...> - 2005-01-06 17:23:16
|
Update of /cvsroot/pclasses/pclasses2/src/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21977/src/System Modified Files: File.posix.cpp Log Message: Added File::unlink() Index: File.posix.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/src/System/File.posix.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- File.posix.cpp 3 Jan 2005 13:50:45 -0000 1.11 +++ File.posix.cpp 6 Jan 2005 17:23:07 -0000 1.12 @@ -301,6 +301,12 @@ return FileInfo(path); } +void File::unlink(const Unicode::String& path) throw(IO::IOError) +{ + if(::unlink(path.utf8().c_str()) == -1) + throw IO::IOError(errno, "Could not unlink file", P_SOURCEINFO); +} + } // !namespace System } // !namespace P |
From: Christian P. <cp...@us...> - 2005-01-06 17:23:16
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/System In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21977/include/pclasses/System Modified Files: File.h Log Message: Added File::unlink() Index: File.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/include/pclasses/System/File.h,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- File.h 3 Jan 2005 13:50:44 -0000 1.9 +++ File.h 6 Jan 2005 17:23:06 -0000 1.10 @@ -70,6 +70,8 @@ static FileInfo stat(const Unicode::String& path) throw(IO::IOError); + static void unlink(const Unicode::String& path) throw(IO::IOError); + protected: /** Frees any resources associated with this object, like filehandles. |