Stream.h

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

Generated on Mon Aug 30 19:10:00 2010 for Vidalia by  doxygen 1.5.9