reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
TransactionState.hxx
Go to the documentation of this file.
1#if !defined(RESIP_TRANSACTIONSTATE_HXX)
2#define RESIP_TRANSACTIONSTATE_HXX
3
4#include <iosfwd>
5#include <memory>
11
12namespace resip
13{
14
15class DnsResult;
16class TransactionMessage;
17class TimerMessage;
18class SendData;
19class TransactionMap;
20class TransactionController;
21class TransactionUser;
22class NameAddr;
23class Via;
24class MessageDecorator;
25
30{
31 public:
33
34 static uint64_t DnsGreylistDurationMs; // The amount of time to greylist a DNS entry for after receiving a transport error
35
36 static void process(TransactionController& controller,
37 TransactionMessage* message);
38 static void processTimer(TransactionController& controller,
39 TimerMessage* timer);
41
42 private:
43 typedef enum
44 {
45 ClientNonInvite,
46 ClientInvite,
47 ServerNonInvite,
48 ServerInvite,
49 ClientStale,
50 ServerStale,
51 Stateless // may not be needed
52 } Machine;
53
54 typedef enum
55 {
56 Calling,
57 Trying,
58 Proceeding,
59 Completed,
60 Confirmed,
61 Terminated,
62 Bogus
63 } State;
64
65 typedef enum
66 {
67 None,
68 Dns
69 } PendingOperation;
70
71 TransactionState(TransactionController& controller,
72 Machine m,
73 State s,
74 const Data& tid,
75 MethodTypes method,
76 const Data& methodText,
77 TransactionUser* tu=0);
78
79 void rewriteRequest(const Uri& rewrite);
80 void handle(DnsResult*);
81 void handleSync(DnsResult*);
82
83 void processStateless(TransactionMessage* msg);
84 void processClientNonInvite(TransactionMessage* msg);
85 void processClientInvite(TransactionMessage* msg);
86 void processServerNonInvite(TransactionMessage* msg);
87 void processServerInvite(TransactionMessage* msg);
88 void processClientStale(TransactionMessage* msg);
89 void processServerStale(TransactionMessage* msg);
90 void processTransportFailure(TransactionMessage* failure);
91 void processTcpConnectState(TransactionMessage* msg);
92 void processNoDnsResults();
93 void processReliability(TransportType type);
94
95 void add(const Data& tid);
96 void erase(const Data& tid);
97
98 bool isClient() const;
99 private:
100 bool isRequest(TransactionMessage* msg) const;
101 bool isInvite(TransactionMessage* msg) const;
102 bool isTimer(TransactionMessage* msg) const;
103 bool isResponse(TransactionMessage* msg, int lower=100, int upper=699) const;
104 bool isFromTU(TransactionMessage* msg) const;
105 bool isFromWire(TransactionMessage* msg) const;
106 bool isTransportError(TransactionMessage* msg) const;
107 bool isTcpConnectState(TransactionMessage* msg) const;
108 bool isSentReliable(TransactionMessage* msg) const;
109 bool isSentUnreliable(TransactionMessage* msg) const;
110 bool isReliabilityIndication(TransactionMessage* msg) const;
111 bool isSentIndication(TransactionMessage* msg) const;
112 bool isAbandonServerTransaction(TransactionMessage* msg) const;
113 bool isCancelClientTransaction(TransactionMessage* msg) const;
114 void sendToTU(TransactionMessage* msg);
115 static void sendToTU(TransactionUser* tu, TransactionController& controller, TransactionMessage* msg);
116 void sendCurrentToWire();
117 void onSendSuccess();
118 SipMessage* make100(SipMessage* request) const;
119 void terminateClientTransaction(const Data& tid);
120 void terminateServerTransaction(const Data& tid);
121 const Data& tid(SipMessage* sip) const;
122
123 void startServerNonInviteTimerTrying(SipMessage& sip, const Data& tid);
124
125 static TransactionState* makeCancelTransaction(TransactionState* tran, Machine machine, const Data& tid);
126 static void handleInternalCancel(SipMessage* cancel,
127 TransactionState& clientInvite);
134 static bool handleBadRequest(const resip::SipMessage& badReq,TransactionController& controller);
135
136 void saveOriginalContactAndVia(const SipMessage& msg);
137 void restoreOriginalContactAndVia();
138 void resetNextTransmission(SipMessage* msg)
139 {
140 delete mNextTransmission;
141 mNextTransmission=msg;
142 mMsgToRetransmit.clear();
143 }
144
145 static bool processSipMessageAsNew(resip::SipMessage* sip,
147 const resip::Data& tid);
148
149 TransactionController& mController;
150
151 Machine mMachine;
152 State mState;
153 bool mIsAbandoned; // TU doesn't care about this transaction anymore.
154 Tokens* mPendingCancelReasons; // Using a pointer to keep storage to a minimum when not needed
155 void setPendingCancelReasons(const Tokens* reasons);
156
157 // Indicates that the message has been sent with a reliable protocol. Set
158 // by the TransportSelector
159 bool mIsReliable;
160
161 // !bwc! sendCurrentToWire() uses these to determine what it should put on
162 // the wire. If mMsgToRetransmit is non-empty, it goes on the wire
163 // _regardless_ of what mNextTransmission is. If mMsgToRetransmit is
164 // empty, but mNextTransmission is non-null, sendCurrentToWire() will try
165 // to send it.
166 SipMessage* mNextTransmission;
167 SendData mMsgToRetransmit;
168
169 // Handle to the dns results queried by the TransportSelector
170 DnsResult* mDnsResult;
171
172 // current selection from the DnsResult. e.g. it is important to send the
173 // CANCEL to exactly the same tuple as the original INVITE went to.
174 Tuple mTarget;
175 Tuple mResponseTarget; // used to reply to requests
176
177 // used when the DnsResult moves to another transport on failure. Only
178 // used for outgoing stateful, so unique_ptr for space efficiency.
179 std::unique_ptr<NameAddr> mOriginalContact;
180 std::unique_ptr<Via> mOriginalVia;
181
182 const Data mId;
183 const MethodTypes mMethod;
184 Data* mMethodText;
185
186 // These two apply to the message we're currently retransmitting.
187 MethodTypes mCurrentMethodType;
188 unsigned int mCurrentResponseCode;
189
190 bool mAckIsValid;
191 PendingOperation mPendingOperation;
192 TransactionUser* mTransactionUser;
193 TransportFailure::FailureReason mFailureReason;
194 int mFailureSubCode;
195 bool mTcpConnectTimerStarted;
196
197 static uint32_t StatelessIdCounter;
198
201};
202
204
205}
206
207#endif
208
209/* ====================================================================
210 * The Vovida Software License, Version 1.0
211 *
212 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
213 *
214 * Redistribution and use in source and binary forms, with or without
215 * modification, are permitted provided that the following conditions
216 * are met:
217 *
218 * 1. Redistributions of source code must retain the above copyright
219 * notice, this list of conditions and the following disclaimer.
220 *
221 * 2. Redistributions in binary form must reproduce the above copyright
222 * notice, this list of conditions and the following disclaimer in
223 * the documentation and/or other materials provided with the
224 * distribution.
225 *
226 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
227 * and "Vovida Open Communication Application Library (VOCAL)" must
228 * not be used to endorse or promote products derived from this
229 * software without prior written permission. For written
230 * permission, please contact vocal@vovida.org.
231 *
232 * 4. Products derived from this software may not be called "VOCAL", nor
233 * may "VOCAL" appear in their name, without prior written
234 * permission of Vovida Networks, Inc.
235 *
236 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
237 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
238 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
239 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
240 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
241 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
242 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
243 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
244 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
245 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
246 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
247 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
248 * DAMAGE.
249 *
250 * ====================================================================
251 *
252 * This software consists of voluntary contributions made by Vovida
253 * Networks, Inc. and many individuals on behalf of Vovida Networks,
254 * Inc. For more information on Vovida Networks, Inc., please see
255 * <http://www.vovida.org/>.
256 *
257 */
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
Represents a SIP message.
static void processTimer(TransactionController &controller, TimerMessage *timer)
static uint64_t DnsGreylistDurationMs
static void process(TransactionController &controller, TransactionMessage *message)
friend EncodeStream & operator<<(EncodeStream &strm, const TransactionState &state)
RESIP_HeapCount(TransactionState)
dcm! – add UnusedChecking(_enum) below;
ParserContainer< Token > Tokens
Definition Headers.hxx:114
unsigned long long uint64_t
Definition Stun.hxx:39
TransportType
An enumeration of transport protocols.
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
#define EncodeStream
unsigned int uint32_t
Definition stdint.h:85
void list()
Definition userAdmin.cxx:66