00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If 00004 ** you did not receive the LICENSE file with this file, you may obtain it 00005 ** from the Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to 00008 ** the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file stream.h 00013 ** \version $Id: stream.h 2510 2008-04-12 22:02:24Z edmanm $ 00014 ** \brief Object representing a Tor stream 00015 */ 00016 00017 #ifndef _STREAM_H 00018 #define _STREAM_H 00019 00020 #include <QCoreApplication> 00021 #include <QString> 00022 #include <QObject> 00023 #include <QList> 00024 00025 00026 class Stream 00027 { 00028 Q_DECLARE_TR_FUNCTIONS(Stream) 00029 00030 public: 00031 /** Stream status values */ 00032 enum Status { 00033 Unknown, /**< Unknown status type given */ 00034 New, /**< New request to connect */ 00035 NewResolve, /**< New request to resolve an address */ 00036 SentConnect, /**< Sent a connect cell */ 00037 SentResolve, /**< Sent a resolve cell */ 00038 Succeeded, /**< Stream established */ 00039 Failed, /**< Stream failed */ 00040 Closed, /**< Stream closed */ 00041 Detached, /**< Detached from circuit */ 00042 Remap /**< Address re-mapped to another */ 00043 }; 00044 00045 /** Default constructor */ 00046 Stream(); 00047 /** Constructor */ 00048 Stream(quint64 streamId, Status status, quint64 circuitId, QString target); 00049 /** Constructor */ 00050 Stream(quint64 streamId, Status status, quint64 circuitId, 00051 QString address, quint16 port); 00052 00053 /** Parses the given string for a stream, in Tor control protocol format. */ 00054 static Stream fromString(QString stream); 00055 /** Converts a string description of a stream's status to its enum value */ 00056 static Status toStatus(QString strStatus); 00057 00058 /** Returns true if the Stream object's fields are all empty. */ 00059 bool isEmpty() const; 00060 00061 /** Returns the ID for this stream. */ 00062 quint64 id() const { return _streamId; } 00063 /** Returns the status for this stream. */ 00064 Status status() const { return _status; } 00065 /** Returns a string representation of this stream's status. */ 00066 QString statusString() const; 00067 /** Returns the ID of the circuit to which this stream is assigned. */ 00068 quint64 circuitId() const { return _circuitId; } 00069 /** Returns the target address and port for this stream. */ 00070 QString target() const { return (_address + ":" + QString::number(_port)); } 00071 /** Returns the target address for this stream. */ 00072 QString targetAddress() const { return _address; } 00073 /** Returns the target port for this stream. */ 00074 quint16 targetPort() const { return _port; } 00075 00076 private: 00077 quint64 _streamId; /**< Unique ID associated with this stream. */ 00078 Status _status; /**< Stream status value. */ 00079 quint64 _circuitId; /**< ID of the circuit carrying this stream. */ 00080 QString _address; /**< Stream target address. */ 00081 quint16 _port; /**< Stream target port. */ 00082 }; 00083 00084 /** A collection of Stream objects. */ 00085 typedef QList<Stream> StreamList; 00086 00087 #endif 00088