#include <BALL/SYSTEM/TCPTransfer.h>
Classes | |
class | TransferFailed |
Public Types | |
enum | Status { OK = 0, GETHOSTBYNAME__ERROR, SOCKET__ERROR, CONNECT__ERROR, RECV__ERROR, OUTOFMEMORY__ERROR, BODY__ERROR, UNKNOWN__ERROR, ADDRESS__ERROR, UNINITIALIZED__ERROR, TRANSFER__ERROR, SEND__ERROR, PORT__ERROR, UNKNOWN_PROTOCOL__ERROR, LOGON__ERROR, PROXY__ERROR, FILENOTFOUND__ERROR = 404 } |
enum | Protocol { UNKNOWN_PROTOCOL = 0, HTTP_PROTOCOL = 1, FTP_PROTOCOL = 2 } |
typedef int | Socket |
typdef for Socket | |
Public Member Functions | |
TCPTransfer () | |
TCPTransfer (std::ostream &file, const String &address) throw (TransferFailed) | |
virtual | ~TCPTransfer () |
Destructor. | |
void | clear () |
bool | set (::std::ostream &file, const String &address) |
void | set (::std::ostream &file, Protocol protocol, const String &host_address, const String &file_address, const String &login, const String &password, Position port=80) |
const String & | getHostAddress () const |
const String & | getFileAddress () const |
Return the file address. | |
Position | getPort () const |
Return the port number. | |
Status | getStatusCode () const |
String | getErrorCode () const |
Position | getReceivedBytes () const |
Return the amount of received bytes. | |
Protocol | getProtocol () const |
const String & | getLogin () const |
Return the login. | |
const String & | getPassword () const |
Return the password. | |
const ::std::ostream * | getStream () const |
Get a pointer to the stream. | |
const char * | getBuffer () const |
Status | transfer () |
void | setProxy (const String proxy_address, Position port) |
bool | usingProxy () const |
void | abort () |
abort a running transfer | |
void | dump (std::ostream &s=std::cout, Size depth=0) const |
Static Public Attributes | |
static const int | TIMEOUT |
Protected Member Functions | |
Status | sendData_ (const String &query, Socket socket) |
Status | logon_ (const String &query) |
Status | getFTP_ () |
Status | getHTTP_ () |
bool | getFTPMessage_ (Index status) |
Status | getFTPStatus_ () |
Status | getHTTPStatus_ () |
Status | setBlock_ (Socket socket, bool block=true) |
bool | waitForOutput_ (const String &key, Size seconds) |
int | getReceivedBytes_ (Socket &socket) |
int | readInputFromSocket_ (Socket &socket) |
Protected Attributes | |
String | host_address_ |
String | file_address_ |
Position | port_ |
String | login_ |
String | password_ |
Status | status_ |
int | received_bytes_ |
Protocol | protocol_ |
char | buffer_ [BUFFER_SIZE+1] |
Socket | socket_ |
std::ostream * | fstream_ |
String | proxy_address_ |
Position | proxy_port_ |
bool | abort_ |
Private Member Functions | |
void | operator= (TCPTransfer) |
Class for TCPTransfers. You can use http and ftp protocol to transfer files from the internet and store them in an ostream. Support for login, password and port is build in for FTP and HTTP. FTP transports are done by passive FTP, so no problems with local firewalls are encountered.
typedef int BALL::TCPTransfer::Socket |
typdef for Socket
Enumeration of some status codes. In addition to these TCPTransfer can also return the status codes of HTTP and FTP.
BALL::TCPTransfer::TCPTransfer | ( | ) |
Default constructor. The instance is set to UNINITIALIZED__ERROR.
BALL::TCPTransfer::TCPTransfer | ( | std::ostream & | file, |
const String & | address | ||
) | throw (TransferFailed) |
Detailled constructor. The file from the given address is downloaded and stored in the ostream instance. You can specify protocol, port and a login/pass by using the syntax:
virtual BALL::TCPTransfer::~TCPTransfer | ( | ) | [virtual] |
Destructor.
void BALL::TCPTransfer::abort | ( | ) | [inline] |
abort a running transfer
void BALL::TCPTransfer::clear | ( | ) |
Clear method. All attributes are set to default values and the status is set to UNINITIALIZED__ERROR.
void BALL::TCPTransfer::dump | ( | std::ostream & | s = std::cout , |
Size | depth = 0 |
||
) | const |
Dump the content of the buffer to an ostream.
s | the stream to which we will dump |
depth | the indentation depth of the output |
const char* BALL::TCPTransfer::getBuffer | ( | ) | const [inline] |
Return a pointer to the buffer. Remember that the buffer may contain NULL-chars. The length of the buffer is less than BUFFER_LENGTH. This method should only be used for debuging.
String BALL::TCPTransfer::getErrorCode | ( | ) | const |
const String& BALL::TCPTransfer::getFileAddress | ( | ) | const [inline] |
Return the file address.
Status BALL::TCPTransfer::getFTP_ | ( | ) | [protected] |
Status BALL::TCPTransfer::getFTPStatus_ | ( | ) | [protected] |
const String& BALL::TCPTransfer::getHostAddress | ( | ) | const [inline] |
Return the host address.
Status BALL::TCPTransfer::getHTTP_ | ( | ) | [protected] |
Status BALL::TCPTransfer::getHTTPStatus_ | ( | ) | [protected] |
const String& BALL::TCPTransfer::getLogin | ( | ) | const [inline] |
Return the login.
const String& BALL::TCPTransfer::getPassword | ( | ) | const [inline] |
Return the password.
Position BALL::TCPTransfer::getPort | ( | ) | const [inline] |
Return the port number.
Position BALL::TCPTransfer::getReceivedBytes | ( | ) | const [inline] |
Return the amount of received bytes.
int BALL::TCPTransfer::getReceivedBytes_ | ( | Socket & | socket | ) | [protected] |
const ::std::ostream* BALL::TCPTransfer::getStream | ( | ) | const [inline] |
Get a pointer to the stream.
void BALL::TCPTransfer::operator= | ( | TCPTransfer | ) | [private] |
int BALL::TCPTransfer::readInputFromSocket_ | ( | Socket & | socket | ) | [protected] |
Reads input from 'socket', waiting if there is a network connection problem (as long as specified by TIMEOUT)
Set method. You can set a new file and address, but the transfer is not yet done. To do that, use transfer() afterwards.
void BALL::TCPTransfer::set | ( | ::std::ostream & | file, |
Protocol | protocol, | ||
const String & | host_address, | ||
const String & | file_address, | ||
const String & | login, | ||
const String & | password, | ||
Position | port = 80 |
||
) |
Detailled set method.
Status BALL::TCPTransfer::transfer | ( | ) |
Transfer method. If the address is specified, the file can be transfered with this method.
bool BALL::TCPTransfer::usingProxy | ( | ) | const |
bool BALL::TCPTransfer::abort_ [protected] |
char BALL::TCPTransfer::buffer_[BUFFER_SIZE+1] [protected] |
String BALL::TCPTransfer::file_address_ [protected] |
std::ostream* BALL::TCPTransfer::fstream_ [protected] |
String BALL::TCPTransfer::host_address_ [protected] |
String BALL::TCPTransfer::login_ [protected] |
String BALL::TCPTransfer::password_ [protected] |
Position BALL::TCPTransfer::port_ [protected] |
Protocol BALL::TCPTransfer::protocol_ [protected] |
String BALL::TCPTransfer::proxy_address_ [protected] |
Position BALL::TCPTransfer::proxy_port_ [protected] |
int BALL::TCPTransfer::received_bytes_ [protected] |
Socket BALL::TCPTransfer::socket_ [protected] |
Status BALL::TCPTransfer::status_ [protected] |
const int BALL::TCPTransfer::TIMEOUT [static] |