00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file stream.h 00024 * \version $Id: stream.h 1796 2007-07-03 01:28:52Z edmanm $ 00025 * \brief Object representing a Tor stream 00026 */ 00027 00028 #ifndef _STREAM_H 00029 #define _STREAM_H 00030 00031 #include <QCoreApplication> 00032 #include <QString> 00033 #include <QObject> 00034 00035 class Stream 00036 { 00037 Q_DECLARE_TR_FUNCTIONS(Stream) 00038 00039 public: 00040 /** Stream status values */ 00041 enum Status { 00042 Unknown, /**< Unknown status type given */ 00043 New, /**< New request to connect */ 00044 NewResolve, /**< New request to resolve an address */ 00045 SentConnect, /**< Sent a connect cell */ 00046 SentResolve, /**< Sent a resolve cell */ 00047 Succeeded, /**< Stream established */ 00048 Failed, /**< Stream failed */ 00049 Closed, /**< Stream closed */ 00050 Detached /**< Detached from circuit */ 00051 }; 00052 00053 /** Default constructor */ 00054 Stream(); 00055 /** Constructor */ 00056 Stream(quint64 streamId, Status status, quint64 circuitId, QString target); 00057 /** Constructor */ 00058 Stream(quint64 streamId, Status status, quint64 circuitId, 00059 QString address, quint16 port); 00060 00061 /** Parses the given string for a stream, in Tor control protocol format. */ 00062 static Stream fromString(QString stream); 00063 /** Converts a string description of a stream's status to its enum value */ 00064 static Status toStatus(QString strStatus); 00065 00066 /** Returns true if the Stream object's fields are all empty. */ 00067 bool isEmpty(); 00068 00069 /** Returns the ID for this stream. */ 00070 quint64 id() { return _streamId; } 00071 /** Returns the status for this stream. */ 00072 Status status() { return _status; } 00073 /** Returns a string representation of this stream's status. */ 00074 QString statusString(); 00075 /** Returns the ID of the circuit to which this stream is assigned. */ 00076 quint64 circuitId() { return _circuitId; } 00077 /** Returns the target address and port for this stream. */ 00078 QString target() { return (_address + ":" + QString::number(_port)); } 00079 /** Returns the target address for this stream. */ 00080 QString targetAddress() { return _address; } 00081 /** Returns the target port for this stream. */ 00082 quint16 targetPort() { return _port; } 00083 00084 private: 00085 quint64 _streamId; /**< Unique ID associated with this stream. */ 00086 Status _status; /**< Stream status value. */ 00087 quint64 _circuitId; /**< ID of the circuit carrying this stream. */ 00088 QString _address; /**< Stream target address. */ 00089 quint16 _port; /**< Stream target port. */ 00090 }; 00091 00092 #endif 00093