OPAL  Version 3.18.8
h323trans.h
Go to the documentation of this file.
1 /*
2  * h323trans.h
3  *
4  * H.323 Transactor handler
5  *
6  * Open H323 Library
7  *
8  * Copyright (c) 2003 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open H323 Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef OPAL_H323_H323TRANS_H
28 #define OPAL_H323_H323TRANS_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #include <opal_config.h>
35 
36 #if OPAL_H323
37 
38 #include <h323/transaddr.h>
39 #include <h323/h235auth.h>
40 
41 #include <ptclib/asner.h>
42 
43 
44 class H323EndPoint;
45 
46 
48  public:
50  H323TransactionPDU(const H235Authenticators & auth);
51 
52  virtual ~H323TransactionPDU() { }
53 
54  virtual PBoolean Read(H323Transport & transport);
55  virtual PBoolean Write(H323Transport & transport);
56 
57  virtual PASN_Object & GetPDU() = 0;
58  virtual PASN_Choice & GetChoice() = 0;
59  virtual const PASN_Object & GetPDU() const = 0;
60  virtual const PASN_Choice & GetChoice() const = 0;
61  virtual unsigned GetSequenceNumber() const = 0;
62  virtual unsigned GetRequestInProgressDelay() const = 0;
63 #if PTRACING
64  virtual const char * GetProtocolName() const = 0;
65 #endif
66  virtual H323TransactionPDU * ClonePDU() const = 0;
67  virtual void DeletePDU() = 0;
68 
69  const H235Authenticators & GetAuthenticators() const { return authenticators; }
70  H235Authenticators & GetAuthenticators() { return authenticators; }
72  const H235Authenticators & auth
73  ) { authenticators = auth; }
74 
75  template <class RAS> H235Authenticator::ValidationResult Validate(const RAS & ras) const
76  {
77  return authenticators.ValidatePDU(*this, ras, rawPDU);
78  }
79 
80  template <class PDU> void Prepare(PDU & pdu)
81  {
82  authenticators.PreparePDU(*this, pdu);
83  }
84 
85  const PBYTEArray & GetRawPDU() const { return rawPDU; }
86 
87  protected:
88  mutable H235Authenticators authenticators;
89  PPER_Stream rawPDU;
90 };
91 
92 
94 
95 class H323Transactor : public PObject
96 {
97  PCLASSINFO(H323Transactor, PObject);
98  public:
101 
105  H323EndPoint & endpoint,
106  H323Transport * transport,
107  WORD localPort,
108  WORD remotePort
109  );
111  H323EndPoint & endpoint,
112  const H323TransportAddress & iface,
113  WORD localPort,
114  WORD remotePort
115  );
116 
119  ~H323Transactor();
121 
126  void PrintOn(
127  ostream & strm
128  ) const;
130 
135  PBoolean SetTransport(
136  const H323TransportAddress & iface
137  );
138 
141  virtual PBoolean StartChannel();
142 
146  virtual void StopChannel();
147 
150  virtual H323TransactionPDU * CreateTransactionPDU() const = 0;
151 
154  virtual PBoolean HandleTransaction(
155  const PASN_Object & rawPDU
156  ) = 0;
157 
160  virtual void OnSendingPDU(
161  PASN_Object & rawPDU
162  ) = 0;
163 
166  virtual PBoolean WritePDU(
167  H323TransactionPDU & pdu
168  );
169 
172  virtual PBoolean WriteTo(
173  H323TransactionPDU & pdu,
174  const H323TransportAddressArray & addresses,
175  PBoolean callback = true
176  );
178 
183  H323EndPoint & GetEndPoint() const { return m_endpoint; }
184 
187  H323Transport & GetTransport() const { return *m_transport; }
188 
192  PBoolean value
193  ) { m_checkResponseCryptoTokens = value; }
194 
199 
200  protected:
201  void Construct();
202 
203  unsigned GetNextSequenceNumber();
204  PBoolean SetUpCallSignalAddresses(
205  H225_ArrayOf_TransportAddress & addresses
206  );
207 
208  //Background thread handler.
209  PDECLARE_NOTIFIER(PThread, H323Transactor, HandleTransactions);
210 
211  class Request : public PObject
212  {
213  PCLASSINFO(Request, PObject);
214  public:
215  Request(
216  unsigned seqNum,
217  H323TransactionPDU & pdu,
219  );
220 
221  PBoolean Poll(H323Transactor &,
222  unsigned numRetries = 0,
223  const PTimeInterval & timeout = 0);
224  void CheckResponse(unsigned, const PASN_Choice *);
225  void OnReceiveRIP(unsigned milliseconds);
226 
230 
231  // Inter-thread transfer variables
232  unsigned m_rejectReason;
233  PObject * m_responseInfo;
234 
235  enum {
244 
245  PTimeInterval m_whenResponseExpected;
246  PSyncPoint m_responseHandled;
247  PDECLARE_MUTEX(m_responseMutex);
248  };
249 
250  virtual PBoolean MakeRequest(
251  Request & request
252  );
253  PBoolean CheckForResponse(
254  unsigned,
255  unsigned,
256  const PASN_Choice * = NULL
257  );
258  PBoolean HandleRequestInProgress(
259  const H323TransactionPDU & pdu,
260  unsigned delay
261  );
262  bool CheckCryptoTokens1(const H323TransactionPDU & pdu);
263  bool CheckCryptoTokens2();
264  template <class RAS> bool CheckCryptoTokens(
265  const H323TransactionPDU & pdu,
266  const RAS & ras
267  ) { return CheckCryptoTokens1(pdu) || (pdu.Validate(ras) == H235Authenticator::e_OK || CheckCryptoTokens2()); }
268 
269  void AgeResponses();
270  PBoolean SendCachedResponse(
271  const H323TransactionPDU & pdu
272  );
273 
274  class Response : public PString
275  {
276  PCLASSINFO(Response, PString);
277  public:
278  Response(const H323TransportAddress & addr, unsigned seqNum);
279  ~Response();
280 
281  void SetPDU(const H323TransactionPDU & pdu);
282  PBoolean SendCachedResponse(H323Transport & transport);
283 
285  PTimeInterval m_retirementAge;
287  };
288 
289  // Configuration variables
295 
296  atomic<uint16_t> m_nextSequenceNumber;
297 
298  PDictionary<POrdinalKey, Request> m_requests;
299  PDECLARE_MUTEX( m_requestsMutex);
301 
302  PDECLARE_MUTEX( m_pduWriteMutex);
303  PSortedList<Response> m_responses;
304 };
305 
306 
308 
309 class H323Transaction : public PObject
310 {
311  PCLASSINFO(H323Transaction, PObject);
312  public:
318  H323Transactor & transactor,
319  const H323TransactionPDU & requestToCopy,
320  H323TransactionPDU * confirm,
321  H323TransactionPDU * reject
322  );
325 
326  enum Response {
327  Ignore = -2,
328  Reject = -1,
330  };
331  inline static Response InProgress(unsigned time) { return (Response)(time&0xffff); }
332 
333  virtual H323TransactionPDU * CreateRIP(
334  unsigned sequenceNumber,
335  unsigned delay
336  ) const = 0;
337 
338  PBoolean HandlePDU();
339 
340  virtual PBoolean WritePDU(
341  H323TransactionPDU & pdu
342  );
343 
344  virtual void PrepareConfirm() { }
345 
346  virtual bool CheckCryptoTokens();
347 
348 #if PTRACING
349  virtual const char * GetName() const = 0;
350 #endif
352  virtual unsigned GetSecurityRejectTag() const { return 0; }
353  virtual void SetRejectReason(
354  unsigned reasonCode
355  ) = 0;
356 
358  PBoolean CanSendRIP() const { return m_canSendRIP; }
361  PBoolean IsBehindNAT() const { return m_isBehindNAT; }
364  void SetAuthenticators(const H235Authenticators & auth) { m_authenticators = auth; }
365 
366  protected:
367  virtual Response OnHandlePDU() = 0;
368  PDECLARE_NOTIFIER(PThread, H323Transaction, SlowHandler);
369 
377 
378  H235Authenticators m_authenticators;
382 };
383 
384 
386 
387 class H323TransactionServer : public PObject
388 {
389  PCLASSINFO(H323TransactionServer, PObject);
390  public:
396  H323EndPoint & endpoint
397  );
398 
403 
404  virtual WORD GetDefaultUdpPort() = 0;
405 
411 
425  PBoolean AddListeners(
426  const H323TransportAddressArray & ifaces
427  );
428 
432  PBoolean AddListener(
433  const H323TransportAddress & interfaceName
434  );
435 
442  PBoolean AddListener(
443  H323Transport * transport
444  );
445 
452  PBoolean AddListener(
453  H323Transactor * listener
454  );
455 
464  virtual H323Transactor * CreateListener(
465  H323Transport * transport
466  ) = 0;
467 
471  PBoolean RemoveListener(
472  H323Transactor * listener
473  );
474 
475  PBoolean SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress & addresses);
477 
478  protected:
480 
481  PThread * m_monitorThread;
482  PSyncPoint m_monitorExit;
483 
484  PDECLARE_MUTEX(m_mutex);
485 
486  PLIST(ListenerList, H323Transactor);
487  ListenerList m_listeners;
488 };
489 
490 
491 #endif // OPAL_H323
492 
493 #endif // OPAL_H323_H323TRANS_H
494 
495 
PBoolean HandlePDU()
virtual PBoolean HandleTransaction(const PASN_Object &rawPDU)=0
Response(const H323TransportAddress &addr, unsigned seqNum)
Definition: h323trans.h:237
bool m_fastResponseRequired
Definition: h323trans.h:373
virtual PASN_Choice & GetChoice()=0
PString GetName(const OpalMediaType &mediaType)
PBoolean AddListener(const H323TransportAddress &interfaceName)
const H235Authenticators & GetAuthenticators() const
Definition: h323trans.h:69
H323EndPoint & m_endpoint
Definition: h323trans.h:290
PDECLARE_NOTIFIER(PThread, H323Transactor, HandleTransactions)
virtual PBoolean MakeRequest(Request &request)
H323TransactionPDU & m_requestPDU
Definition: h323trans.h:228
virtual PBoolean WritePDU(H323TransactionPDU &pdu)
PBoolean SendCachedResponse(const H323TransactionPDU &pdu)
PTimeInterval m_whenResponseExpected
Definition: h323trans.h:245
PObject * m_responseInfo
Definition: h323trans.h:233
virtual void OnSendingPDU(PASN_Object &rawPDU)=0
virtual bool CheckCryptoTokens()
PSortedList< Response > m_responses
Definition: h323trans.h:303
H323TransportAddressArray m_requestAddresses
Definition: h323trans.h:229
virtual unsigned GetRequestInProgressDelay() const =0
H235Authenticator::ValidationResult GetAuthenticatorResult() const
Definition: h323trans.h:363
void SetAuthenticators(const H235Authenticators &auth)
Definition: h323trans.h:71
WORD m_defaultLocalPort
Definition: h323trans.h:291
H323Transport * m_transport
Definition: h323trans.h:293
H323TransactionPDU * m_request
Definition: h323trans.h:374
Definition: transports.h:788
virtual H235Authenticator::ValidationResult ValidatePDU() const =0
H323TransactionPDU * m_replyPDU
Definition: h323trans.h:286
unsigned m_rejectReason
Definition: h323trans.h:232
H323EndPoint & GetOwnerEndPoint() const
Definition: h323trans.h:410
bool m_isBehindNAT
Definition: h323trans.h:380
ListenerList m_listeners
Definition: h323trans.h:487
virtual void PrepareConfirm()
Definition: h323trans.h:344
Definition: h323trans.h:309
Definition: h323trans.h:95
H323Transactor(H323EndPoint &endpoint, H323Transport *transport, WORD localPort, WORD remotePort)
PBoolean CanSendRIP() const
Definition: h323trans.h:358
PBoolean IsBehindNAT() const
Definition: h323trans.h:361
PLIST(ListenerList, H323Transactor)
unsigned m_requestSequenceNumber
Definition: h323trans.h:371
virtual ~H323TransactionPDU()
Definition: h323trans.h:52
PBoolean AddListeners(const H323TransportAddressArray &ifaces)
Definition: h323trans.h:238
Definition: h323trans.h:327
H235Authenticators authenticators
Definition: h323trans.h:88
PPER_Stream rawPDU
Definition: h323trans.h:89
PSyncPoint m_monitorExit
Definition: h323trans.h:482
virtual PASN_Object & GetPDU()=0
virtual unsigned GetSequenceNumber() const =0
Definition: h323trans.h:329
Request * m_lastRequest
Definition: h323trans.h:300
void PrintOn(ostream &strm) const
virtual unsigned GetSecurityRejectTag() const
Definition: h323trans.h:352
virtual PBoolean WritePDU(H323TransactionPDU &pdu)
virtual PBoolean StartChannel()
virtual H323Transactor * CreateListener(H323Transport *transport)=0
Definition: h323trans.h:274
Definition: transaddr.h:91
Definition: h323trans.h:328
PBoolean Poll(H323Transactor &, unsigned numRetries=0, const PTimeInterval &timeout=0)
enum H323Transactor::Request::@22 m_responseResult
H323Transport & GetTransport() const
Definition: h323trans.h:187
void CheckResponse(unsigned, const PASN_Choice *)
virtual void SetRejectReason(unsigned reasonCode)=0
virtual WORD GetDefaultUdpPort()=0
PBoolean CheckForResponse(unsigned, unsigned, const PASN_Choice *=NULL)
Definition: h323trans.h:240
H235Authenticators m_authenticators
Definition: h323trans.h:378
virtual void DeletePDU()=0
bool CheckCryptoTokens(const H323TransactionPDU &pdu, const RAS &ras)
Definition: h323trans.h:264
void OnReceiveRIP(unsigned milliseconds)
H235Authenticator::ValidationResult m_authenticatorResult
Definition: h323trans.h:379
H323Transactor & GetTransactor() const
Definition: h323trans.h:362
virtual H323TransactionPDU * CreateRIP(unsigned sequenceNumber, unsigned delay) const =0
H323TransactionServer(H323EndPoint &endpoint)
PDECLARE_NOTIFIER(PThread, H323Transaction, SlowHandler)
H323Transaction(H323Transactor &transactor, const H323TransactionPDU &requestToCopy, H323TransactionPDU *confirm, H323TransactionPDU *reject)
static Response InProgress(unsigned time)
Definition: h323trans.h:331
unsigned m_sequenceNumber
Definition: h323trans.h:227
void SetCheckResponseCryptoTokens(PBoolean value)
Definition: h323trans.h:191
H235Authenticators & GetAuthenticators()
Definition: h323trans.h:70
Definition: h323trans.h:211
Definition: h235auth.h:83
PBoolean HandleRequestInProgress(const H323TransactionPDU &pdu, unsigned delay)
PDictionary< POrdinalKey, Request > m_requests
Definition: h323trans.h:298
virtual PBoolean Read(H323Transport &transport)
H323EndPoint & GetEndPoint() const
Definition: h323trans.h:183
virtual H323TransactionPDU * ClonePDU() const =0
H323TransactionPDU * m_confirm
Definition: h323trans.h:375
PBoolean SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress &addresses)
virtual PBoolean Write(H323Transport &transport)
PBoolean IsFastResponseRequired() const
Definition: h323trans.h:357
bool m_canSendRIP
Definition: h323trans.h:381
PBoolean SendCachedResponse(H323Transport &transport)
Definition: h323trans.h:47
ValidationResult
Definition: h235auth.h:82
PTimeInterval m_retirementAge
Definition: h323trans.h:285
H323TransportAddress GetReplyAddress() const
Definition: h323trans.h:359
H235Authenticator::ValidationResult Validate(const RAS &ras) const
Definition: h323trans.h:75
Definition: h323trans.h:387
PSyncPoint m_responseHandled
Definition: h323trans.h:246
Request(unsigned seqNum, H323TransactionPDU &pdu, const H323TransportAddressArray &addresses=H323TransportAddressArray())
bool m_checkResponseCryptoTokens
Definition: h323trans.h:294
PBoolean RemoveListener(H323Transactor *listener)
H323TransactionPDU * m_reject
Definition: h323trans.h:376
void SetPDU(const H323TransactionPDU &pdu)
H323TransportAddressArray m_replyAddresses
Definition: h323trans.h:372
PBoolean GetCheckResponseCryptoTokens()
Definition: h323trans.h:197
bool CheckCryptoTokens2()
virtual H323TransactionPDU * CreateTransactionPDU() const =0
bool CheckCryptoTokens1(const H323TransactionPDU &pdu)
PBoolean SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress &addresses)
PDECLARE_MUTEX(m_requestsMutex)
const H323TransportAddressArray & GetReplyAddresses() const
Definition: h323trans.h:360
PBoolean SetTransport(const H323TransportAddress &iface)
virtual Response OnHandlePDU()=0
Response
Definition: h323trans.h:326
void AgeResponses()
unsigned GetNextSequenceNumber()
Definition: h323ep.h:82
void SetAuthenticators(const H235Authenticators &auth)
Definition: h323trans.h:364
virtual void StopChannel()
PDECLARE_MUTEX(m_responseMutex)
WORD m_defaultRemotePort
Definition: h323trans.h:292
H323Transactor & m_transactor
Definition: h323trans.h:370
Definition: transaddr.h:62
void Prepare(PDU &pdu)
Definition: h323trans.h:80
Definition: h323trans.h:239
const PBYTEArray & GetRawPDU() const
Definition: h323trans.h:85
PThread * m_monitorThread
Definition: h323trans.h:481
virtual PBoolean WriteTo(H323TransactionPDU &pdu, const H323TransportAddressArray &addresses, PBoolean callback=true)
H323EndPoint & m_ownerEndPoint
Definition: h323trans.h:479
atomic< uint16_t > m_nextSequenceNumber
Definition: h323trans.h:296
PTime m_lastUsedTime
Definition: h323trans.h:284