h323trans.h
Go to the documentation of this file.
/*
* h323trans.h
*
* H.323 Transactor handler
*
* Open H323 Library
*
* Copyright (c) 2003 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Open H323 Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24178 $
* $Author: rjongbloed $
* $Date: 2010-04-05 19:10:56 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef OPAL_H323_H323TRANS_H
#define OPAL_H323_H323TRANS_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <opal/buildopts.h>
#if OPAL_H323
#include <h323/transaddr.h>
#include <h323/h235auth.h>
#include <ptclib/asner.h>
class H323EndPoint;
class H323TransactionPDU {
public:
H323TransactionPDU();
H323TransactionPDU(const H235Authenticators & auth);
virtual ~H323TransactionPDU() { }
virtual PBoolean Read(H323Transport & transport);
virtual PBoolean Write(H323Transport & transport);
virtual PASN_Object & GetPDU() = 0;
virtual PASN_Choice & GetChoice() = 0;
virtual const PASN_Object & GetPDU() const = 0;
virtual const PASN_Choice & GetChoice() const = 0;
virtual unsigned GetSequenceNumber() const = 0;
virtual unsigned GetRequestInProgressDelay() const = 0;
#if PTRACING
virtual const char * GetProtocolName() const = 0;
#endif
virtual H323TransactionPDU * ClonePDU() const = 0;
virtual void DeletePDU() = 0;
const H235Authenticators & GetAuthenticators() const { return authenticators; }
H235Authenticators & GetAuthenticators() { return authenticators; }
void SetAuthenticators(
const H235Authenticators & auth
) { authenticators = auth; }
H235Authenticator::ValidationResult Validate(
const PASN_Array & clearTokens,
unsigned clearOptionalField,
const PASN_Array & cryptoTokens,
unsigned cryptoOptionalField
) const { return authenticators.ValidatePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField, rawPDU); }
void Prepare(
PASN_Array & clearTokens,
unsigned clearOptionalField,
PASN_Array & cryptoTokens,
unsigned cryptoOptionalField
) { authenticators.PreparePDU(*this, clearTokens, clearOptionalField, cryptoTokens, cryptoOptionalField); }
protected:
mutable H235Authenticators authenticators;
PPER_Stream rawPDU;
};
class H323Transactor : public PObject
{
PCLASSINFO(H323Transactor, PObject);
public:
H323Transactor(
H323EndPoint & endpoint,
H323Transport * transport,
WORD localPort,
WORD remotePort
);
H323Transactor(
H323EndPoint & endpoint,
const H323TransportAddress & iface,
WORD localPort,
WORD remotePort
);
~H323Transactor();
void PrintOn(
ostream & strm
) const;
PBoolean SetTransport(
const H323TransportAddress & iface
);
H323TransportAddressArray GetInterfaceAddresses(
bool excludeLocalHost = true
);
virtual PBoolean StartChannel();
virtual void StopChannel();
virtual H323TransactionPDU * CreateTransactionPDU() const = 0;
virtual PBoolean HandleTransaction(
const PASN_Object & rawPDU
) = 0;
virtual void OnSendingPDU(
PASN_Object & rawPDU
) = 0;
virtual PBoolean WritePDU(
H323TransactionPDU & pdu
);
virtual PBoolean WriteTo(
H323TransactionPDU & pdu,
const H323TransportAddressArray & addresses,
PBoolean callback = true
);
H323EndPoint & GetEndPoint() const { return endpoint; }
H323Transport & GetTransport() const { return *transport; }
void SetCheckResponseCryptoTokens(
PBoolean value
) { checkResponseCryptoTokens = value; }
PBoolean GetCheckResponseCryptoTokens() { return checkResponseCryptoTokens; }
protected:
void Construct();
unsigned GetNextSequenceNumber();
PBoolean SetUpCallSignalAddresses(
H225_ArrayOf_TransportAddress & addresses
);
//Background thread handler.
PDECLARE_NOTIFIER(PThread, H323Transactor, HandleTransactions);
class Request : public PObject
{
PCLASSINFO(Request, PObject);
public:
Request(
unsigned seqNum,
H323TransactionPDU & pdu
);
Request(
unsigned seqNum,
H323TransactionPDU & pdu,
const H323TransportAddressArray & addresses
);
PBoolean Poll(H323Transactor &,
unsigned numRetries = 0,
PTimeInterval timeout = 0);
void CheckResponse(unsigned, const PASN_Choice *);
void OnReceiveRIP(unsigned milliseconds);
// Inter-thread transfer variables
unsigned rejectReason;
void * responseInfo;
H323TransportAddressArray requestAddresses;
unsigned sequenceNumber;
H323TransactionPDU & requestPDU;
PTimeInterval whenResponseExpected;
PSyncPoint responseHandled;
PMutex responseMutex;
enum {
AwaitingResponse,
ConfirmReceived,
RejectReceived,
TryAlternate,
BadCryptoTokens,
RequestInProgress,
NoResponseReceived
} responseResult;
};
virtual PBoolean MakeRequest(
Request & request
);
PBoolean CheckForResponse(
unsigned,
unsigned,
const PASN_Choice * = NULL
);
PBoolean HandleRequestInProgress(
const H323TransactionPDU & pdu,
unsigned delay
);
PBoolean CheckCryptoTokens(
const H323TransactionPDU & pdu,
const PASN_Array & clearTokens,
unsigned clearOptionalField,
const PASN_Array & cryptoTokens,
unsigned cryptoOptionalField
);
void AgeResponses();
PBoolean SendCachedResponse(
const H323TransactionPDU & pdu
);
class Response : public PString
{
PCLASSINFO(Response, PString);
public:
Response(const H323TransportAddress & addr, unsigned seqNum);
~Response();
void SetPDU(const H323TransactionPDU & pdu);
PBoolean SendCachedResponse(H323Transport & transport);
PTime lastUsedTime;
PTimeInterval retirementAge;
H323TransactionPDU * replyPDU;
};
// Configuration variables
H323EndPoint & endpoint;
WORD defaultLocalPort;
WORD defaultRemotePort;
H323Transport * transport;
PBoolean checkResponseCryptoTokens;
unsigned nextSequenceNumber;
PMutex nextSequenceNumberMutex;
PDictionary<POrdinalKey, Request> requests;
PMutex requestsMutex;
Request * lastRequest;
PMutex pduWriteMutex;
PSortedList<Response> responses;
};
class H323Transaction : public PObject
{
PCLASSINFO(H323Transaction, PObject);
public:
H323Transaction(
H323Transactor & transactor,
const H323TransactionPDU & requestToCopy,
H323TransactionPDU * confirm,
H323TransactionPDU * reject
);
~H323Transaction();
enum Response {
Ignore = -2,
Reject = -1,
Confirm = 0
};
inline static Response InProgress(unsigned time) { return (Response)(time&0xffff); }
virtual H323TransactionPDU * CreateRIP(
unsigned sequenceNumber,
unsigned delay
) const = 0;
PBoolean HandlePDU();
virtual PBoolean WritePDU(
H323TransactionPDU & pdu
);
PBoolean CheckCryptoTokens(
const H235Authenticators & authenticators
);
#if PTRACING
virtual const char * GetName() const = 0;
#endif
virtual H235Authenticator::ValidationResult ValidatePDU() const = 0;
virtual void SetRejectReason(
unsigned reasonCode
) = 0;
PBoolean IsFastResponseRequired() const { return fastResponseRequired && canSendRIP; }
PBoolean CanSendRIP() const { return canSendRIP; }
H323TransportAddress GetReplyAddress() const { return replyAddresses[0]; }
const H323TransportAddressArray & GetReplyAddresses() const { return replyAddresses; }
PBoolean IsBehindNAT() const { return isBehindNAT; }
H323Transactor & GetTransactor() const { return transactor; }
H235Authenticator::ValidationResult GetAuthenticatorResult() const { return authenticatorResult; }
protected:
virtual Response OnHandlePDU() = 0;
PDECLARE_NOTIFIER(PThread, H323Transaction, SlowHandler);
H323Transactor & transactor;
unsigned requestSequenceNumber;
H323TransportAddressArray replyAddresses;
PBoolean fastResponseRequired;
H323TransactionPDU * request;
H323TransactionPDU * confirm;
H323TransactionPDU * reject;
H235Authenticators authenticators;
H235Authenticator::ValidationResult authenticatorResult;
PBoolean isBehindNAT;
PBoolean canSendRIP;
};
class H323TransactionServer : public PObject
{
PCLASSINFO(H323TransactionServer, PObject);
public:
H323TransactionServer(
H323EndPoint & endpoint
);
~H323TransactionServer();
virtual WORD GetDefaultUdpPort() = 0;
H323EndPoint & GetOwnerEndPoint() const { return ownerEndPoint; }
PBoolean AddListeners(
const H323TransportAddressArray & ifaces
);
PBoolean AddListener(
const H323TransportAddress & interfaceName
);
PBoolean AddListener(
H323Transport * transport
);
PBoolean AddListener(
H323Transactor * listener
);
virtual H323Transactor * CreateListener(
H323Transport * transport
) = 0;
PBoolean RemoveListener(
H323Transactor * listener
);
PBoolean SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress & addresses);
protected:
H323EndPoint & ownerEndPoint;
PThread * monitorThread;
PSyncPoint monitorExit;
PMutex mutex;
PLIST(ListenerList, H323Transactor);
ListenerList listeners;
};
#endif // OPAL_H323
#endif // OPAL_H323_H323TRANS_H
H323Transactor::Request::requestAddresses
H323TransportAddressArray requestAddresses
Definition: h323trans.h:247
H323Transaction::HandlePDU
PBoolean HandlePDU()
H323Transactor::pduWriteMutex
PMutex pduWriteMutex
Definition: h323trans.h:320
H323Transactor::HandleTransaction
virtual PBoolean HandleTransaction(const PASN_Object &rawPDU)=0
H323Transactor::Response::Response
Response(const H323TransportAddress &addr, unsigned seqNum)
H323Transactor::Request::RequestInProgress
Definition: h323trans.h:261
H323TransactionPDU::GetChoice
virtual PASN_Choice & GetChoice()=0
H323Transactor::Request::BadCryptoTokens
Definition: h323trans.h:260
H323TransactionServer::AddListener
PBoolean AddListener(const H323TransportAddress &interfaceName)
H323TransactionPDU::GetAuthenticators
const H235Authenticators & GetAuthenticators() const
Definition: h323trans.h:73
H323Transactor::checkResponseCryptoTokens
PBoolean checkResponseCryptoTokens
Definition: h323trans.h:311
H323TransportAddressArray
H323TransportAddressArray(const OpalTransportAddress &address)
Definition: transaddr.h:97
H323Transactor::PDECLARE_NOTIFIER
PDECLARE_NOTIFIER(PThread, H323Transactor, HandleTransactions)
H323Transactor::MakeRequest
virtual PBoolean MakeRequest(Request &request)
H323Transaction::WritePDU
virtual PBoolean WritePDU(H323TransactionPDU &pdu)
H323Transactor::defaultRemotePort
WORD defaultRemotePort
Definition: h323trans.h:309
H323Transactor::SendCachedResponse
PBoolean SendCachedResponse(const H323TransactionPDU &pdu)
buildopts.h
H323Transactor::OnSendingPDU
virtual void OnSendingPDU(PASN_Object &rawPDU)=0
H323TransactionPDU::GetRequestInProgressDelay
virtual unsigned GetRequestInProgressDelay() const =0
H323Transaction::GetAuthenticatorResult
H235Authenticator::ValidationResult GetAuthenticatorResult() const
Definition: h323trans.h:380
H323TransactionPDU::SetAuthenticators
void SetAuthenticators(const H235Authenticators &auth)
Definition: h323trans.h:75
OpalTransport
Definition: transports.h:703
H323Transaction::ValidatePDU
virtual H235Authenticator::ValidationResult ValidatePDU() const =0
H323Transactor::Request::whenResponseExpected
PTimeInterval whenResponseExpected
Definition: h323trans.h:251
H323TransactionServer::GetOwnerEndPoint
H323EndPoint & GetOwnerEndPoint() const
Definition: h323trans.h:426
H323Transaction::confirm
H323TransactionPDU * confirm
Definition: h323trans.h:391
H323Transactor::Request::sequenceNumber
unsigned sequenceNumber
Definition: h323trans.h:249
H323Transaction
Definition: h323trans.h:327
H323Transactor
Definition: h323trans.h:101
H323Transactor::H323Transactor
H323Transactor(H323EndPoint &endpoint, H323Transport *transport, WORD localPort, WORD remotePort)
H323TransactionServer::ownerEndPoint
H323EndPoint & ownerEndPoint
Definition: h323trans.h:495
H323Transaction::CanSendRIP
PBoolean CanSendRIP() const
Definition: h323trans.h:375
H323Transaction::IsBehindNAT
PBoolean IsBehindNAT() const
Definition: h323trans.h:378
H323Transactor::Request::requestPDU
H323TransactionPDU & requestPDU
Definition: h323trans.h:250
H323TransactionServer::PLIST
PLIST(ListenerList, H323Transactor)
H323TransactionPDU::~H323TransactionPDU
virtual ~H323TransactionPDU()
Definition: h323trans.h:56
H323TransactionServer::AddListeners
PBoolean AddListeners(const H323TransportAddressArray &ifaces)
H323Transaction::Ignore
Definition: h323trans.h:345
H323TransactionPDU::authenticators
H235Authenticators authenticators
Definition: h323trans.h:94
H323TransactionPDU::rawPDU
PPER_Stream rawPDU
Definition: h323trans.h:95
H323TransactionPDU::Prepare
void Prepare(PASN_Array &clearTokens, unsigned clearOptionalField, PASN_Array &cryptoTokens, unsigned cryptoOptionalField)
Definition: h323trans.h:86
H323Transaction::canSendRIP
PBoolean canSendRIP
Definition: h323trans.h:397
H323TransactionPDU::GetPDU
virtual PASN_Object & GetPDU()=0
H323TransactionPDU::GetSequenceNumber
virtual unsigned GetSequenceNumber() const =0
H323Transaction::Confirm
Definition: h323trans.h:347
H323Transactor::PrintOn
void PrintOn(ostream &strm) const
H323Transactor::responses
PSortedList< Response > responses
Definition: h323trans.h:321
H323Transactor::Request::responseResult
enum H323Transactor::Request::@18 responseResult
H323TransactionServer::~H323TransactionServer
~H323TransactionServer()
H323Transactor::WritePDU
virtual PBoolean WritePDU(H323TransactionPDU &pdu)
H323Transactor::StartChannel
virtual PBoolean StartChannel()
H323Transactor::Request::RejectReceived
Definition: h323trans.h:258
H323Transaction::isBehindNAT
PBoolean isBehindNAT
Definition: h323trans.h:396
H323TransactionServer::CreateListener
virtual H323Transactor * CreateListener(H323Transport *transport)=0
H323Transactor::Response
Definition: h323trans.h:291
H323Transactor::requests
PDictionary< POrdinalKey, Request > requests
Definition: h323trans.h:316
H323Transaction::~H323Transaction
~H323Transaction()
H323Transaction::Reject
Definition: h323trans.h:346
H323Transactor::GetTransport
H323Transport & GetTransport() const
Definition: h323trans.h:199
H323Transaction::authenticators
H235Authenticators authenticators
Definition: h323trans.h:394
H323Transactor::Request::CheckResponse
void CheckResponse(unsigned, const PASN_Choice *)
H323Transaction::SetRejectReason
virtual void SetRejectReason(unsigned reasonCode)=0
H323Transactor::Response::retirementAge
PTimeInterval retirementAge
Definition: h323trans.h:302
H323TransactionServer::GetDefaultUdpPort
virtual WORD GetDefaultUdpPort()=0
H323Transactor::CheckForResponse
PBoolean CheckForResponse(unsigned, unsigned, const PASN_Choice *=NULL)
H323Transactor::Request::responseHandled
PSyncPoint responseHandled
Definition: h323trans.h:252
H323Transactor::Response::lastUsedTime
PTime lastUsedTime
Definition: h323trans.h:301
H323TransactionPDU::DeletePDU
virtual void DeletePDU()=0
H323Transaction::replyAddresses
H323TransportAddressArray replyAddresses
Definition: h323trans.h:388
H323Transactor::Request::OnReceiveRIP
void OnReceiveRIP(unsigned milliseconds)
H323Transactor::GetInterfaceAddresses
H323TransportAddressArray GetInterfaceAddresses(bool excludeLocalHost=true)
H323Transaction::GetTransactor
H323Transactor & GetTransactor() const
Definition: h323trans.h:379
h235auth.h
H323Transactor::Response::~Response
~Response()
H323Transactor::Request::rejectReason
unsigned rejectReason
Definition: h323trans.h:244
H323Transaction::CreateRIP
virtual H323TransactionPDU * CreateRIP(unsigned sequenceNumber, unsigned delay) const =0
H323TransactionServer::H323TransactionServer
H323TransactionServer(H323EndPoint &endpoint)
H323Transaction::PDECLARE_NOTIFIER
PDECLARE_NOTIFIER(PThread, H323Transaction, SlowHandler)
H323Transactor::lastRequest
Request * lastRequest
Definition: h323trans.h:318
H323Transaction::H323Transaction
H323Transaction(H323Transactor &transactor, const H323TransactionPDU &requestToCopy, H323TransactionPDU *confirm, H323TransactionPDU *reject)
H323Transaction::CheckCryptoTokens
PBoolean CheckCryptoTokens(const H235Authenticators &authenticators)
H323Transaction::InProgress
static Response InProgress(unsigned time)
Definition: h323trans.h:349
H323Transaction::reject
H323TransactionPDU * reject
Definition: h323trans.h:392
H323Transactor::SetCheckResponseCryptoTokens
void SetCheckResponseCryptoTokens(PBoolean value)
Definition: h323trans.h:203
H323TransactionPDU::GetAuthenticators
H235Authenticators & GetAuthenticators()
Definition: h323trans.h:74
H323TransactionServer::monitorThread
PThread * monitorThread
Definition: h323trans.h:497
H323Transactor::Request
Definition: h323trans.h:223
H323Transactor::HandleRequestInProgress
PBoolean HandleRequestInProgress(const H323TransactionPDU &pdu, unsigned delay)
H323Transaction::request
H323TransactionPDU * request
Definition: h323trans.h:390
H323TransactionPDU::Read
virtual PBoolean Read(H323Transport &transport)
H323Transactor::~H323Transactor
~H323Transactor()
H323Transactor::GetEndPoint
H323EndPoint & GetEndPoint() const
Definition: h323trans.h:195
H323TransactionPDU::ClonePDU
virtual H323TransactionPDU * ClonePDU() const =0
H323Transaction::requestSequenceNumber
unsigned requestSequenceNumber
Definition: h323trans.h:387
H323Transactor::CheckCryptoTokens
PBoolean CheckCryptoTokens(const H323TransactionPDU &pdu, const PASN_Array &clearTokens, unsigned clearOptionalField, const PASN_Array &cryptoTokens, unsigned cryptoOptionalField)
H323TransactionServer::SetUpCallSignalAddresses
PBoolean SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress &addresses)
H323TransactionPDU::Write
virtual PBoolean Write(H323Transport &transport)
H323Transaction::IsFastResponseRequired
PBoolean IsFastResponseRequired() const
Definition: h323trans.h:374
H323Transactor::Response::SendCachedResponse
PBoolean SendCachedResponse(H323Transport &transport)
H323TransactionPDU
Definition: h323trans.h:51
H235Authenticator::ValidationResult
ValidationResult
Definition: h235auth.h:83
H323Transaction::GetReplyAddress
H323TransportAddress GetReplyAddress() const
Definition: h323trans.h:376
H323TransactionServer
Definition: h323trans.h:403
H323Transaction::transactor
H323Transactor & transactor
Definition: h323trans.h:386
H323TransactionServer::RemoveListener
PBoolean RemoveListener(H323Transactor *listener)
H323TransactionPDU::Validate
H235Authenticator::ValidationResult Validate(const PASN_Array &clearTokens, unsigned clearOptionalField, const PASN_Array &cryptoTokens, unsigned cryptoOptionalField) const
Definition: h323trans.h:79
H323Transactor::Response::replyPDU
H323TransactionPDU * replyPDU
Definition: h323trans.h:303
H323Transactor::Response::SetPDU
void SetPDU(const H323TransactionPDU &pdu)
H323Transactor::GetCheckResponseCryptoTokens
PBoolean GetCheckResponseCryptoTokens()
Definition: h323trans.h:209
H323Transactor::nextSequenceNumberMutex
PMutex nextSequenceNumberMutex
Definition: h323trans.h:314
H323TransactionServer::monitorExit
PSyncPoint monitorExit
Definition: h323trans.h:498
H323Transactor::Request::Poll
PBoolean Poll(H323Transactor &, unsigned numRetries=0, PTimeInterval timeout=0)
H323Transactor::Request::responseMutex
PMutex responseMutex
Definition: h323trans.h:253
H323Transactor::CreateTransactionPDU
virtual H323TransactionPDU * CreateTransactionPDU() const =0
H323Transactor::SetUpCallSignalAddresses
PBoolean SetUpCallSignalAddresses(H225_ArrayOf_TransportAddress &addresses)
H323Transactor::nextSequenceNumber
unsigned nextSequenceNumber
Definition: h323trans.h:313
H323Transaction::GetReplyAddresses
const H323TransportAddressArray & GetReplyAddresses() const
Definition: h323trans.h:377
H323Transactor::SetTransport
PBoolean SetTransport(const H323TransportAddress &iface)
transaddr.h
H323Transaction::OnHandlePDU
virtual Response OnHandlePDU()=0
H323Transactor::Request::Request
Request(unsigned seqNum, H323TransactionPDU &pdu)
H323Transaction::authenticatorResult
H235Authenticator::ValidationResult authenticatorResult
Definition: h323trans.h:395
H323Transaction::Response
Response
Definition: h323trans.h:344
H323Transactor::AgeResponses
void AgeResponses()
H323Transactor::GetNextSequenceNumber
unsigned GetNextSequenceNumber()
H323TransactionPDU::H323TransactionPDU
H323TransactionPDU()
H323TransactionServer::listeners
ListenerList listeners
Definition: h323trans.h:502
H323EndPoint
Definition: h323ep.h:85
H323TransactionServer::mutex
PMutex mutex
Definition: h323trans.h:500
H323Transactor::Request::NoResponseReceived
Definition: h323trans.h:262
H323Transactor::Request::ConfirmReceived
Definition: h323trans.h:257
H323Transactor::StopChannel
virtual void StopChannel()
H323Transactor::Construct
void Construct()
H323Transactor::endpoint
H323EndPoint & endpoint
Definition: h323trans.h:307
H323Transaction::fastResponseRequired
PBoolean fastResponseRequired
Definition: h323trans.h:389
H323TransportAddress
Definition: transaddr.h:66
H323Transactor::WriteTo
virtual PBoolean WriteTo(H323TransactionPDU &pdu, const H323TransportAddressArray &addresses, PBoolean callback=true)
H323Transactor::transport
H323Transport * transport
Definition: h323trans.h:310
H323Transactor::requestsMutex
PMutex requestsMutex
Definition: h323trans.h:317
H323Transactor::Request::TryAlternate
Definition: h323trans.h:259
H323Transactor::Request::responseInfo
void * responseInfo
Definition: h323trans.h:245
H323Transactor::Request::AwaitingResponse
Definition: h323trans.h:256
H323Transactor::defaultLocalPort
WORD defaultLocalPort
Definition: h323trans.h:308