Stun Server  Compliant with the latest RFCs including 5389, 5769, and 5780
discover the local host's own external IP address
messagehandler.h
Go to the documentation of this file.
1 /*
2  Copyright 2011 John Selbie
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 
18 #ifndef MESSAGEHANDLER_H_
19 #define MESSAGEHANDLER_H_
20 
21 #include "stunauth.h"
22 #include "socketrole.h"
23 
25 {
30  bool fConnectionOriented; // true for TCP or TLS (where we can't send back to a different port)
31 };
32 
34 {
35  SocketRole socketrole; // which socket to send out to (ignored for TCP)
36  CSocketAddress addrDest; // where to send the response to (ignored for TCP)
37  CRefCountedBuffer spBufferOut; // allocated by the caller - output message
38 };
39 
40 
42 {
44 
46  char szUser[MAX_STUN_AUTH_STRING_SIZE+1]; // used for computing the message-integrity value
47  char szRealm[MAX_STUN_AUTH_STRING_SIZE+1]; // used for computing the message-integrity value
48  char szPassword[MAX_STUN_AUTH_STRING_SIZE+1]; // used for computing the message-integrity value
49 };
50 
52 {
54  bool fValid; // set to false if not valid (basic mode and most TCP/SSL scenarios)
55 };
56 
58 {
59  TransportAddress set[4]; // one for each socket role RolePP, RolePA, RoleAP, and RoleAA
60 };
61 
63 {
64  uint16_t errorcode;
66  uint16_t msgtype;
67  uint16_t attribUnknown; // for now, just send back one unknown attribute at a time
68  char szNonce[MAX_STUN_AUTH_STRING_SIZE+1];
69  char szRealm[MAX_STUN_AUTH_STRING_SIZE+1];
70 };
71 
72 
73 
74 
76 {
77 public:
78  static HRESULT ProcessRequest(const StunMessageIn& msgIn, StunMessageOut& msgOut, TransportAddressSet* pAddressSet, /*optional*/ IStunAuth* pAuth);
79 private:
80 
82 
83  HRESULT ProcessBindingRequest();
84  void BuildErrorResponse();
85  HRESULT ValidateAuth();
86  HRESULT ProcessRequestImpl();
87 
88  // input
93 
94  // member variables to remember along the way
97 
101 
102  bool HasAddress(SocketRole role);
103  bool IsIPAddressZeroOrInvalid(SocketRole role);
104 };
105 
106 
107 #endif /* MESSAGEHANDLER_H_ */
TransportAddressSet * _pAddrSet
StunErrorCode _error
StunMessageIntegrity _integrity
SocketRole socketrole
SocketRole socketrole
CSocketAddress addr
uint16_t attribUnknown
StunTransactionId _transid
CSocketAddress addrRemote
What local IP address the message was received on (useful if the socket binded to INADDR_ANY) ...
CSocketAddress addrLocal
which socket id did the message arrive on
uint16_t msgtype
const uint32_t MAX_STUN_AUTH_STRING_SIZE
Definition: stunauth.h:22
SocketRole
Definition: socketrole.h:22
StunMessageClass msgclass
int32_t HRESULT
Definition: hresult.h:22
StunMessageClass
Definition: stuntypes.h:93
CSocketAddress addrDest
StunMessageOut * _pMsgOut
CStunMessageReader * pReader
the address of the node that sent us the message
CRefCountedBuffer spBufferOut
boost::shared_ptr< CBuffer > CRefCountedBuffer
Definition: buffer.h:65
const StunMessageIn * _pMsgIn
uint16_t errorcode
bool fConnectionOriented
reader containing a valid stun message