OPAL  Version 3.12.9
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  * $Revision: 24178 $
27  * $Author: rjongbloed $
28  * $Date: 2010-04-06 10:10:56 +1000 (Tue, 06 Apr 2010) $
29  */
30 
31 #ifndef OPAL_H323_H323TRANS_H
32 #define OPAL_H323_H323TRANS_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <opal/buildopts.h>
39 
40 #if OPAL_H323
41 
42 #include <h323/transaddr.h>
43 #include <h323/h235auth.h>
44 
45 #include <ptclib/asner.h>
46 
47 
48 class H323EndPoint;
49 
50 
52  public:
54  H323TransactionPDU(const H235Authenticators & auth);
55 
56  virtual ~H323TransactionPDU() { }
57 
58  virtual PBoolean Read(H323Transport & transport);
59  virtual PBoolean Write(H323Transport & transport);
60 
61  virtual PASN_Object & GetPDU() = 0;
62  virtual PASN_Choice & GetChoice() = 0;
63  virtual const PASN_Object & GetPDU() const = 0;
64  virtual const PASN_Choice & GetChoice() const = 0;
65  virtual unsigned GetSequenceNumber() const = 0;
66  virtual unsigned GetRequestInProgressDelay() const = 0;
67 #if PTRACING
68  virtual const char * GetProtocolName() const = 0;
69 #endif
70  virtual H323TransactionPDU * ClonePDU() const = 0;
71  virtual void DeletePDU() = 0;
72 
73  const H235Authenticators & GetAuthenticators() const { return authenticators; }
74  H235Authenticators & GetAuthenticators() { return authenticators; }
76  const H235Authenticators & auth
77  ) { authenticators = auth; }
78 
80  const PASN_Array & clearTokens,
81  unsigned clearOptionalField,
82  const PASN_Array & cryptoTokens,
83  unsigned cryptoOptionalField
84  ) const { return authenticators.ValidatePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField, rawPDU); }
85 
86  void Prepare(
87  PASN_Array & clearTokens,
88  unsigned clearOptionalField,
89  PASN_Array & cryptoTokens,
90  unsigned cryptoOptionalField
91  ) { authenticators.PreparePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField); }
92 
93  protected:
94  mutable H235Authenticators authenticators;
95  PPER_Stream rawPDU;
96 };
97 
98 
100 
101 class H323Transactor : public PObject
102 {
103  PCLASSINFO(H323Transactor, PObject);
104  public:
107 
113  WORD localPort,
114  WORD remotePort
115  );
117  H323EndPoint & endpoint,
118  const H323TransportAddress & iface,
119  WORD localPort,
120  WORD remotePort
121  );
122 
125  ~H323Transactor();
127 
132  void PrintOn(
133  ostream & strm
134  ) const;
136 
141  PBoolean SetTransport(
142  const H323TransportAddress & iface
143  );
144 
148  bool excludeLocalHost = true
149  );
150 
153  virtual PBoolean StartChannel();
154 
158  virtual void StopChannel();
159 
162  virtual H323TransactionPDU * CreateTransactionPDU() const = 0;
163 
166  virtual PBoolean HandleTransaction(
167  const PASN_Object & rawPDU
168  ) = 0;
169 
172  virtual void OnSendingPDU(
173  PASN_Object & rawPDU
174  ) = 0;
175 
178  virtual PBoolean WritePDU(
179  H323TransactionPDU & pdu
180  );
181 
184  virtual PBoolean WriteTo(
185  H323TransactionPDU & pdu,
186  const H323TransportAddressArray & addresses,
187  PBoolean callback = true
188  );
190 
195  H323EndPoint & GetEndPoint() const { return endpoint; }
196 
199  H323Transport & GetTransport() const { return *transport; }
200 
204  PBoolean value
205  ) { checkResponseCryptoTokens = value; }
206 
211 
212  protected:
213  void Construct();
214 
215  unsigned GetNextSequenceNumber();
216  PBoolean SetUpCallSignalAddresses(
217  H225_ArrayOf_TransportAddress & addresses
218  );
219 
220  //Background thread handler.
221  PDECLARE_NOTIFIER(PThread, H323Transactor, HandleTransactions);
222 
223  class Request : public PObject
224  {
225  PCLASSINFO(Request, PObject);
226  public:
227  Request(
228  unsigned seqNum,
229  H323TransactionPDU & pdu
230  );
231  Request(
232  unsigned seqNum,
233  H323TransactionPDU & pdu,
234  const H323TransportAddressArray & addresses
235  );
236 
237  PBoolean Poll(H323Transactor &,
238  unsigned numRetries = 0,
239  PTimeInterval timeout = 0);
240  void CheckResponse(unsigned, const PASN_Choice *);
241  void OnReceiveRIP(unsigned milliseconds);
242 
243  // Inter-thread transfer variables
244  unsigned rejectReason;
245  void * responseInfo;
246 
248 
249  unsigned sequenceNumber;
251  PTimeInterval whenResponseExpected;
252  PSyncPoint responseHandled;
254 
255  enum {
263  } responseResult;
264  };
265 
266  virtual PBoolean MakeRequest(
267  Request & request
268  );
269  PBoolean CheckForResponse(
270  unsigned,
271  unsigned,
272  const PASN_Choice * = NULL
273  );
274  PBoolean HandleRequestInProgress(
275  const H323TransactionPDU & pdu,
276  unsigned delay
277  );
278  PBoolean CheckCryptoTokens(
279  const H323TransactionPDU & pdu,
280  const PASN_Array & clearTokens,
281  unsigned clearOptionalField,
282  const PASN_Array & cryptoTokens,
283  unsigned cryptoOptionalField
284  );
285 
286  void AgeResponses();
287  PBoolean SendCachedResponse(
288  const H323TransactionPDU & pdu
289  );
290 
291  class Response : public PString
292  {
293  PCLASSINFO(Response, PString);
294  public:
295  Response(const H323TransportAddress & addr, unsigned seqNum);
296  ~Response();
297 
298  void SetPDU(const H323TransactionPDU & pdu);
299  PBoolean SendCachedResponse(H323Transport & transport);
300 
302  PTimeInterval retirementAge;
304  };
305 
306  // Configuration variables
312 
315 
316  PDictionary<POrdinalKey, Request> requests;
319 
321  PSortedList<Response> responses;
322 };
323 
324 
326 
327 class H323Transaction : public PObject
328 {
329  PCLASSINFO(H323Transaction, PObject);
330  public:
337  const H323TransactionPDU & requestToCopy,
340  );
343 
344  enum Response {
345  Ignore = -2,
346  Reject = -1,
348  };
349  inline static Response InProgress(unsigned time) { return (Response)(time&0xffff); }
350 
351  virtual H323TransactionPDU * CreateRIP(
352  unsigned sequenceNumber,
353  unsigned delay
354  ) const = 0;
355 
356  PBoolean HandlePDU();
357 
358  virtual PBoolean WritePDU(
359  H323TransactionPDU & pdu
360  );
361 
362  PBoolean CheckCryptoTokens(
363  const H235Authenticators & authenticators
364  );
365 
366 #if PTRACING
367  virtual const char * GetName() const = 0;
368 #endif
370  virtual void SetRejectReason(
371  unsigned reasonCode
372  ) = 0;
373 
375  PBoolean CanSendRIP() const { return canSendRIP; }
378  PBoolean IsBehindNAT() const { return isBehindNAT; }
381 
382  protected:
383  virtual Response OnHandlePDU() = 0;
384  PDECLARE_NOTIFIER(PThread, H323Transaction, SlowHandler);
385 
393 
394  H235Authenticators authenticators;
396  PBoolean isBehindNAT;
397  PBoolean canSendRIP;
398 };
399 
400 
402 
403 class H323TransactionServer : public PObject
404 {
405  PCLASSINFO(H323TransactionServer, PObject);
406  public:
412  H323EndPoint & endpoint
413  );
414 
419 
420  virtual WORD GetDefaultUdpPort() = 0;
421 
427 
441  PBoolean AddListeners(
442  const H323TransportAddressArray & ifaces
443  );
444 
448  PBoolean AddListener(
449  const H323TransportAddress & interfaceName
450  );
451 
458  PBoolean AddListener(
459  H323Transport * transport
460  );
461 
468  PBoolean AddListener(
469  H323Transactor * listener
470  );
471 
480  virtual H323Transactor * CreateListener(
481  H323Transport * transport
482  ) = 0;
483 
487  PBoolean RemoveListener(
488  H323Transactor * listener
489  );
490 
491  PBoolean SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress & addresses);
493 
494  protected:
496 
497  PThread * monitorThread;
498  PSyncPoint monitorExit;
499 
500  PMutex mutex;
501  PLIST(ListenerList, H323Transactor);
502  ListenerList listeners;
503 };
504 
505 
506 #endif // OPAL_H323
507 
508 #endif // OPAL_H323_H323TRANS_H
509 
510