reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
WsFrameExtractor.hxx
Go to the documentation of this file.
1#ifndef RESIP_WsFrameExtractor_hxx
2#define RESIP_WsFrameExtractor_hxx
3
4#include <memory>
5#include <queue>
6
7#include "rutil/compat.hxx"
8#include "rutil/Data.hxx"
9
10namespace resip
11{
12
14{
15 public:
16
17 // frame opcodes (RFC 6455 section 5.2)
18 static const uint8_t OpContinuation = 0x0;
19 static const uint8_t OpText = 0x1;
20 static const uint8_t OpBinary = 0x2;
21 static const uint8_t OpClose = 0x8;
22 static const uint8_t OpPing = 0x9;
23 static const uint8_t OpPong = 0xA;
24
25 // A Close, Ping or Pong frame. These are never returned by processBytes():
26 // a peer may send one at any time, even between the fragments of a message,
27 // and its payload is not SIP.
33
36 std::unique_ptr<Data> processBytes(uint8_t *input, Data::size_type len, bool& dropConnection);
37 // the control frames received so far, in the order they arrived
38 bool popControlFrame(ControlFrame& frame);
39
40 private:
41
42 static const int mMaxHeaderLen;
43 // an upper bound on the number of frames a single message may be
44 // fragmented into, to stop a peer consuming unbounded memory by
45 // sending an endless run of tiny (or empty) continuation frames
46 static const size_t mMaxFrames;
47
48 Data::size_type mMaxMessage;
49
50 std::queue<Data*> mFrames;
51 std::queue<Data*> mMessages;
52 // for tracking the cumulative size of all full frames
53 // not yet assembled into a message:
54 Data::size_type mMessageSize;
55
56 bool mHaveHeader;
57 int mHeaderLen;
58 uint8_t *mWsHeader;
59
60 std::queue<ControlFrame> mControlFrames;
61 // set once a Close frame has arrived: nothing the peer sends after it is processed
62 bool mClosed;
63
64 bool mFinalFrame;
65 bool mMasked;
66 uint8_t mOpcode;
67 uint8_t mWsMaskKey[4];
68 // the payload length as it appears on the wire: it is a 64 bit
69 // field, so it must be validated against mMaxMessage before it is
70 // used for anything (see processBytes)
71 uint64_t mPayloadLength;
72
73 uint8_t *mPayload;
74 Data::size_type mPayloadPos;
75
76 int parseHeader();
77 bool isControlFrame() const;
78 void joinFrames();
79
80};
81
82}
83
84#endif
85
86/* ====================================================================
87 *
88 * Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
89 * Copyright 2013 Daniel Pocock. All rights reserved.
90 *
91 * Redistribution and use in source and binary forms, with or without
92 * modification, are permitted provided that the following conditions
93 * are met:
94 *
95 * 1. Redistributions of source code must retain the above copyright
96 * notice, this list of conditions and the following disclaimer.
97 *
98 * 2. Redistributions in binary form must reproduce the above copyright
99 * notice, this list of conditions and the following disclaimer in
100 * the documentation and/or other materials provided with the
101 * distribution.
102 *
103 * 3. Neither the name of the author(s) nor the names of any contributors
104 * may be used to endorse or promote products derived from this software
105 * without specific prior written permission.
106 *
107 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
108 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
109 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
110 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
111 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
112 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
113 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
114 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
115 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
116 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
117 * SUCH DAMAGE.
118 *
119 * ====================================================================
120 *
121 *
122 */
123
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
size_t size_type
Definition Data.hxx:94
std::unique_ptr< Data > processBytes(uint8_t *input, Data::size_type len, bool &dropConnection)
static const uint8_t OpClose
static const uint8_t OpText
static const uint8_t OpBinary
static const uint8_t OpPing
bool popControlFrame(ControlFrame &frame)
static const uint8_t OpPong
static const uint8_t OpContinuation
This file is used to handle compatibility fixes/tweaks so reSIProcate can function on multiple platfo...
dcm! – add UnusedChecking(_enum) below;
unsigned long long uint64_t
Definition Stun.hxx:39
unsigned char uint8_t
Definition Stun.hxx:29