reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
ConnectionBase.hxx
Go to the documentation of this file.
1#ifndef RESIP_ConnectionBase_hxx
2#define RESIP_ConnectionBase_hxx
3
4#include <deque>
5#include <list>
6
7#include "rutil/Timer.hxx"
8// #include "rutil/Fifo.hxx"
15
16namespace osc
17{
18 class Stack;
19 class TcpStream;
20}
21
22namespace resip
23{
24
25class TransactionMessage;
26class Compression;
27
39{
41 public:
43 const Tuple& who,
44 Compression &compression = Compression::Disabled);
45 FlowKey getFlowKey() const;
46
48 virtual Transport* transport() const;
49
50 Tuple& who() { return mWho; }
51 const uint64_t& whenLastUsed() { return mLastUsed; }
52 void resetLastUsed() { mLastUsed = Timer::getTimeMs(); }
53
54 void addAdditionalFailureString(const Data& additionalFailureString);
55
56 enum { ChunkSize = 8192 }; // !jf! what is the optimal size here?
57 // !dp! 8192 seems to be consistent with a multiple of a page size and
58 // also good for the larger SDP coming in with ICE attributes,
59 // multiple media streams, etc
60
61 protected:
63 {
67 SigComp, // This indicates that incoming bytes are compressed.
69 MAX
70 };
71
80
81 ConnState getCurrentState() const { return mConnState; }
82 bool preparseNewBytes(int bytesRead);
83 bool wsProcessHandshake(int bytesRead, bool &dropConnection);
84 bool wsProcessData(int bytesRead);
85 void wsParseCookies(CookieList& cookieList, const SipMessage* message);
86 void decompressNewBytes(int bytesRead);
87 std::pair<char*, size_t> getWriteBuffer();
88 std::pair<char*, size_t> getCurrentWriteBuffer();
89 char* getWriteBufferForExtraBytes(int bytesRead, int extraBytes);
90
91 // for avoiding copies in external transports--not used in core resip
92 void setBuffer(char* bytes, int count);
93
95 std::list<SendData*> mOutstandingSends; // !jacob! intrusive queue?
96
97 void setFailureReason(TransportFailure::FailureReason failReason, int subCode, const Data& failureString);
98
99 virtual ~ConnectionBase();
100 // no value semantics
101 private:
104 ConnectionBase& operator=(const Connection&);
105 bool scanMsgHeader(int bytesRead);
106 std::unique_ptr<Data> makeWsHandshakeResponse();
107 bool isUsingSecWebSocketKey();
108 bool isUsingDeprecatedSecWebSocketKeys();
109 const std::shared_ptr<const ConnectionInfo>& getConnectionInfo();
110 protected:
111 virtual void onDoubleCRLF(){}
112 virtual void onSingleCRLF(){}
113 // WebSocket control frames from the peer (RFC 6455 section 5.5); the payload of a
114 // Close is its status code and reason, if it sent any
115 virtual void onWsClose(const Data& payload){}
116 virtual void onWsPing(const Data& payload){}
124 osc::Stack *mSigcompStack;
125 osc::TcpStream *mSigcompFramer;
128
129 private:
130 SipMessage* mMessage;
131 char* mBuffer;
132 size_t mBufferPos;
133 size_t mBufferSize;
134 WsFrameExtractor mWsFrameExtractor;
135
136 static char connectionStates[MAX][32];
137 uint64_t mLastUsed;
138 ConnState mConnState;
139 MsgHeaderScanner mMsgHeaderScanner;
140
141 // TLS/WebSocket details given to every message received on this
142 // connection; built when the first message arrives
143 std::shared_ptr<const ConnectionInfo> mConnectionInfo;
144 bool mConnectionInfoBuilt = false;
145
146 static size_t messageSizeMax;
147
148 public:
149 static void setMessageSizeMax(size_t max)
150 { messageSizeMax = max; };
151};
152
155
156}
157
158#endif
159/* ====================================================================
160 * The Vovida Software License, Version 1.0
161 *
162 * Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
163 * Copyright (c) 2000
164 *
165 * Redistribution and use in source and binary forms, with or without
166 * modification, are permitted provided that the following conditions
167 * are met:
168 *
169 * 1. Redistributions of source code must retain the above copyright
170 * notice, this list of conditions and the following disclaimer.
171 *
172 * 2. Redistributions in binary form must reproduce the above copyright
173 * notice, this list of conditions and the following disclaimer in
174 * the documentation and/or other materials provided with the
175 * distribution.
176 *
177 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
178 * and "Vovida Open Communication Application Library (VOCAL)" must
179 * not be used to endorse or promote products derived from this
180 * software without prior written permission. For written
181 * permission, please contact vocal@vovida.org.
182 *
183 * 4. Products derived from this software may not be called "VOCAL", nor
184 * may "VOCAL" appear in their name, without prior written
185 * permission of Vovida Networks, Inc.
186 *
187 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
188 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
189 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
190 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
191 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
192 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
193 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
194 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
195 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
196 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
197 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
198 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
199 * DAMAGE.
200 *
201 * ====================================================================
202 *
203 * This software consists of voluntary contributions made by Vovida
204 * Networks, Inc. and many individuals on behalf of Vovida Networks,
205 * Inc. For more information on Vovida Networks, Inc., please see
206 * <http://www.vovida.org/>.
207 *
208 */
#define max(x, y)
static Compression Disabled
Represents a compression configuration object with compression disabled.
virtual Transport * transport() const
void setFailureReason(TransportFailure::FailureReason failReason, int subCode, const Data &failureString)
const uint64_t & whenLastUsed()
char * getWriteBufferForExtraBytes(int bytesRead, int extraBytes)
TransmissionFormat mSendingTransmissionFormat
bool wsProcessData(int bytesRead)
virtual void onWsClose(const Data &payload)
osc::TcpStream * mSigcompFramer
std::pair< char *, size_t > getWriteBuffer()
bool wsProcessHandshake(int bytesRead, bool &dropConnection)
void decompressNewBytes(int bytesRead)
TransmissionFormat mReceivingTransmissionFormat
virtual void onSingleCRLF()
friend EncodeStream & operator<<(EncodeStream &strm, const resip::ConnectionBase &c)
static void setMessageSizeMax(size_t max)
std::pair< char *, size_t > getCurrentWriteBuffer()
bool preparseNewBytes(int bytesRead)
std::list< SendData * > mOutstandingSends
void setBuffer(char *bytes, int count)
std::list< Data > mAdditionalFailureStrings
void addAdditionalFailureString(const Data &additionalFailureString)
ConnState getCurrentState() const
virtual void onWsPing(const Data &payload)
void wsParseCookies(CookieList &cookieList, const SipMessage *message)
virtual void onDoubleCRLF()
Data::size_type mSendPos
FlowKey getFlowKey() const
TransportFailure::FailureReason mFailureReason
Connection implements, via sockets, ConnectionBase for managed connections.
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
size_t size_type
Definition Data.hxx:94
Represents a SIP message.
static uint64_t getTimeMs()
Returns the current clock time in milliseconds.
Definition Timer.hxx:72
The base class for Transport classes.
Definition Transport.hxx:83
Represents a network address.
Definition Tuple.hxx:59
dcm! – add UnusedChecking(_enum) below;
unsigned long FlowKey
Definition Tuple.hxx:37
unsigned long long uint64_t
Definition Stun.hxx:39
EncodeStream & operator<<(EncodeStream &strm, const BaseException &e)
std::vector< Cookie > CookieList
Definition Cookie.hxx:35
#define EncodeStream
void list()
Definition userAdmin.cxx:66