Vidalia
0.2.15
|
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.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file Stream.h 00013 ** \brief Object representing a Tor stream 00014 */ 00015 00016 #ifndef _STREAM_H 00017 #define _STREAM_H 00018 00019 #include "Circuit.h" 00020 00021 #include <QCoreApplication> 00022 #include <QString> 00023 #include <QObject> 00024 #include <QList> 00025 #include <QMetaType> 00026 00027 /** Stream IDs contains 1-16 alphanumeric ASCII characters. */ 00028 typedef QString StreamId; 00029 00030 00031 class Stream 00032 { 00033 Q_DECLARE_TR_FUNCTIONS(Stream) 00034 00035 public: 00036 /** Stream status values */ 00037 enum Status { 00038 Unknown, /**< Unknown status type given */ 00039 New, /**< New request to connect */ 00040 NewResolve, /**< New request to resolve an address */ 00041 SentConnect, /**< Sent a connect cell */ 00042 SentResolve, /**< Sent a resolve cell */ 00043 Succeeded, /**< Stream established */ 00044 Failed, /**< Stream failed */ 00045 Closed, /**< Stream closed */ 00046 Detached, /**< Detached from circuit */ 00047 Remap /**< Address re-mapped to another */ 00048 }; 00049 00050 /** Default constructor */ 00051 Stream(); 00052 /** Constructor */ 00053 Stream(const StreamId &streamId, Status status, const CircuitId &circuitId, 00054 const QString &target); 00055 /** Constructor */ 00056 Stream(const StreamId &streamId, Status status, const CircuitId &circuitId, 00057 const QString &address, quint16 port); 00058 00059 /** Parses the given string for a stream, in Tor control protocol format. */ 00060 static Stream fromString(const QString &stream); 00061 /** Converts a string description of a stream's status to its enum value */ 00062 static Status toStatus(const QString &strStatus); 00063 00064 /** Returns true iff the Stream object's fields are all valid. */ 00065 bool isValid() const; 00066 00067 /** Returns the ID for this stream. */ 00068 StreamId id() const { return _streamId; } 00069 /** Returns the status for this stream. */ 00070 Status status() const { return _status; } 00071 /** Returns a string representation of this stream's status. */ 00072 QString statusString() const; 00073 /** Returns the ID of the circuit to which this stream is assigned. */ 00074 CircuitId circuitId() const { return _circuitId; } 00075 /** Returns the target address and port for this stream. */ 00076 QString target() const { return (_address + ":" + QString::number(_port)); } 00077 /** Returns the target address for this stream. */ 00078 QString targetAddress() const { return _address; } 00079 /** Returns the target port for this stream. */ 00080 quint16 targetPort() const { return _port; } 00081 00082 /** Returns true iff <b>streamId</b> consists of only between 1 and 16 00083 * (inclusive) ASCII-encoded letters and numbers. */ 00084 static bool isValidStreamId(const StreamId &streamId); 00085 00086 private: 00087 StreamId _streamId; /**< Unique ID associated with this stream. */ 00088 CircuitId _circuitId; /**< ID of the circuit carrying this stream. */ 00089 QString _address; /**< Stream target address. */ 00090 Status _status; /**< Stream status value. */ 00091 quint16 _port; /**< Stream target port. */ 00092 }; 00093 00094 Q_DECLARE_METATYPE(Stream); 00095 00096 /** A collection of Stream objects. */ 00097 typedef QList<Stream> StreamList; 00098 00099 #endif 00100