Vidalia 0.3.1
Stream.h
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If
4** you did not receive the LICENSE file with this file, you may obtain it
5** from the Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file Stream.h
13** \brief Object representing a Tor stream
14*/
15
16#ifndef _STREAM_H
17#define _STREAM_H
18
19#include "Circuit.h"
20
21#include <QCoreApplication>
22#include <QString>
23#include <QObject>
24#include <QList>
25#include <QMetaType>
26
27/** Stream IDs contains 1-16 alphanumeric ASCII characters. */
28typedef QString StreamId;
29
30
31class Stream
32{
33 Q_DECLARE_TR_FUNCTIONS(Stream)
34
35public:
36 /** Stream status values */
37 enum Status {
38 Unknown, /**< Unknown status type given */
39 New, /**< New request to connect */
40 NewResolve, /**< New request to resolve an address */
41 SentConnect, /**< Sent a connect cell */
42 SentResolve, /**< Sent a resolve cell */
43 Succeeded, /**< Stream established */
44 Failed, /**< Stream failed */
45 Closed, /**< Stream closed */
46 Detached, /**< Detached from circuit */
47 Remap /**< Address re-mapped to another */
48 };
49
50 /** Default constructor */
51 Stream();
52 /** Constructor */
53 Stream(const StreamId &streamId, Status status, const CircuitId &circuitId,
54 const QString &target);
55 /** Constructor */
56 Stream(const StreamId &streamId, Status status, const CircuitId &circuitId,
57 const QString &address, quint16 port);
58
59 /** Parses the given string for a stream, in Tor control protocol format. */
60 static Stream fromString(const QString &stream);
61 /** Converts a string description of a stream's status to its enum value */
62 static Status toStatus(const QString &strStatus);
63
64 /** Returns true iff the Stream object's fields are all valid. */
65 bool isValid() const;
66
67 /** Returns the ID for this stream. */
68 StreamId id() const { return _streamId; }
69 /** Returns the status for this stream. */
70 Status status() const { return _status; }
71 /** Returns a string representation of this stream's status. */
72 QString statusString() const;
73 /** Returns the ID of the circuit to which this stream is assigned. */
74 CircuitId circuitId() const { return _circuitId; }
75 /** Returns the target address and port for this stream. */
76 QString target() const { return (_address + ":" + QString::number(_port)); }
77 /** Returns the target address for this stream. */
78 QString targetAddress() const { return _address; }
79 /** Returns the target port for this stream. */
80 quint16 targetPort() const { return _port; }
81
82 /** Returns true iff <b>streamId</b> consists of only between 1 and 16
83 * (inclusive) ASCII-encoded letters and numbers. */
84 static bool isValidStreamId(const StreamId &streamId);
85
86private:
87 StreamId _streamId; /**< Unique ID associated with this stream. */
88 CircuitId _circuitId; /**< ID of the circuit carrying this stream. */
89 QString _address; /**< Stream target address. */
90 Status _status; /**< Stream status value. */
91 quint16 _port; /**< Stream target port. */
92};
93
95
96/** A collection of Stream objects. */
97typedef QList<Stream> StreamList;
98
99#endif
100
QString CircuitId
Definition: Circuit.h:24
QString StreamId
Definition: Stream.h:28
QList< Stream > StreamList
Definition: Stream.h:97
Q_DECLARE_METATYPE(Stream)
Definition: Stream.h:32
CircuitId _circuitId
Definition: Stream.h:88
StreamId id() const
Definition: Stream.h:68
QString statusString() const
Definition: Stream.cpp:126
static Status toStatus(const QString &strStatus)
Definition: Stream.cpp:100
CircuitId circuitId() const
Definition: Stream.h:74
quint16 targetPort() const
Definition: Stream.h:80
Stream()
Definition: Stream.cpp:23
Status status() const
Definition: Stream.h:70
bool isValid() const
Definition: Stream.cpp:146
static bool isValidStreamId(const StreamId &streamId)
Definition: Stream.cpp:84
Status _status
Definition: Stream.h:90
QString targetAddress() const
Definition: Stream.h:78
QString target() const
Definition: Stream.h:76
StreamId _streamId
Definition: Stream.h:87
Status
Definition: Stream.h:37
@ NewResolve
Definition: Stream.h:40
@ Failed
Definition: Stream.h:44
@ SentResolve
Definition: Stream.h:42
@ New
Definition: Stream.h:39
@ Detached
Definition: Stream.h:46
@ Closed
Definition: Stream.h:45
@ Remap
Definition: Stream.h:47
@ SentConnect
Definition: Stream.h:41
@ Unknown
Definition: Stream.h:38
@ Succeeded
Definition: Stream.h:43
static Stream fromString(const QString &stream)
Definition: Stream.cpp:63
quint16 _port
Definition: Stream.h:91
QString _address
Definition: Stream.h:89