/* * * versuch project * Signalling channel Q931/H225 * CallPool object * $Id: CallThread.h,v 1.4 2006/07/28 14:41:16 warlock_kg Exp $ * warlock copyright since 2005 Nov * */ #ifndef _CALLTHREAD_H #define _CALLTHREAD_H #include "Aaa.h" #include "global.h" #include "MediaProxy.h" #include "ControlThread.h" #include "h245.h" #include "Sockets.h" #include #include #include #include class SignallingThread; class ControlThread; class CallTable; void SendMsg( PPER_Stream & Stream, WTCPSocket * Destination ); struct cntrs { unsigned attempts; unsigned calls; unsigned wm; // watermark }; struct T_signalling_thread_data { SignallingThread * ch; }; class CallThread; struct T_call_thread_data { CallThread * ch; }; class CallThread { public: CallThread(TGlobal & env); virtual ~CallThread(); void Close(); H225_TransportAddress GetCallSignallingAddr(); void Main(); bool IsRunning() const { return Running; }; // Used by children to check when to die void WaitForTermination(); TGlobal & env; struct cntrs counters; CallTable * ClTbl; struct timeval ssStartTime ; struct T_call_thread_data * call_tdata; protected: CallThread(); // Stop clients calling default cons CallThread( const CallThread & ); // ...or copy constructor ControlThread * Control; WTCPSocket CallSocket; bool Running; pthread_t ThreadID; struct newlog_thread_data * rl_tdata; }; class H245Handler; class H245Thread; class TCallPool; class TCDR; class SignallingThread { public: SignallingThread(CallThread * Parent, TGlobal & AkaEnviron, WTCPSocket * RecvSocket ); virtual ~SignallingThread(); void GetCallSignallingAddr( WSocket::Address & CallerAddr, WSocket::Address & CalledAddr, unsigned CallRef ); void GetCallSignallingAddr( in_addr & CallerAddr, in_addr & CalledAddr, unsigned CallRef ); void ClearCall(unsigned CallRef); bool FE_IsAlready(const H225_ArrayOf_PASN_OctetString & FS1, const H225_ArrayOf_PASN_OctetString & FS2, PPER_Stream & strm1, PPER_Stream & strm2); void ShutdownCall(unsigned CallRef); H245Handler* GetH245Handler() { return MyH245Handler; }; void Main(); pthread_t GetThreadName(); CallThread * Parent; TAuth * mAuth; TAcct * mAcct; TGlobal & env; WTCPSocket * CallerSocket; WSocket::Address IncAddr, IncLocalAddr; TMessLog * MessLog; TCallPool * CallPool; string IncProductId, IncVersionId; struct T_signalling_thread_data * signalling_tdata; bool Stop; protected: SignallingThread(); SignallingThread( const SignallingThread & ); void Close(); void ReceiveMesg(WTCPSocket * Socket, bool FromCaller ); void HandleMesg( Q931 & Mesg, bool FromCaller, unsigned & CallRef ); void HandleH245Setup( Q931 & Mesg, H225_H323_UserInformation & UUField, unsigned CallRef, bool FromCaller ); bool HandleSetup( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef, bool Reuse = false); bool HandleProceeding( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef); bool HandleAlerting( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef ); bool HandleConnect( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef ); bool HandleRelease( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef, bool & CloseCall ); bool HandleFacility( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef ); bool HandleProgress( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef ); bool HandleInformation ( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef ); bool HandleNotify ( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef ); void HandleUnknown ( Q931 & Mesg, bool FromCaller, bool HasUU, H225_H323_UserInformation & UUField, unsigned & CallRef ); bool ReHandleSetup(unsigned & CallRef, const int TermCode); bool ConnectToRemote( WSocket::Address & IpAddr, unsigned CallRef ); void HandleTunneledH245( H225_H323_UserInformation & UUField, unsigned CallRef, bool FromCaller ); void SendReleaseComplete( const Q931 & Mesg, WTCPSocket * Destination, Q931::CauseValues cause ); void SendProceeding( const Q931 & SetupMesg, H225_H323_UserInformation & UUField, bool Tunneling, bool multipleCallsS ); void TranslateSetup( H225_Setup_UUIE & Setup, const H225_TransportAddress & SourceCallSigAddr, const H225_TransportAddress & DestCallSigAddr, const string & OutCalledNumber, const string & OutCallingNumber ); void HandleFastStart(H225_ArrayOf_PASN_OctetString & fastStart, bool FromCaller, unsigned CallRef); void HandleFastStartAck(H225_ArrayOf_PASN_OctetString & fastStart, bool FromCaller, unsigned CallRef); void HandleFastStartAck(H225_ArrayOf_PASN_OctetString & fastStart, bool FromCaller, unsigned CallRef, H225_ArrayOf_PASN_OctetString DefferedFS); void CheckTimeout(); void GetDestinationAdress( H225_H323_UserInformation UUField, string & DestDialedDigits); void SetH245Address( Q931 & Mesg, H225_H323_UserInformation & UUField, const H225_TransportAddress & Addr ); void RemoveH245Address( Q931 & Mesg, H225_H323_UserInformation & UUField ); void CheckTunneling(bool HasUU, H225_H323_UserInformation & UUField, bool & Tunnel); void ShutdownCalls(vector & List); H245Handler * MyH245Handler; unsigned int OutDialPeer; bool IsMultyCon; // sign of multiply connections in single signal channel pthread_t ThreadID; bool multipleCallsS; unsigned int CallerPort; }; class MediaThread; // forward declaration class TCallPool { public: enum ConnectionStates { NoConnectionActive = 0, HasExecutedSignalConnect = 1, EstablishedConnection = 2, ShuttingDownConnection = 3, MediaRunning = 4 }; enum FastStartStates { NoFastStart = 0, FastStartResponse = 1, FastStartAcknowledged = 2 }; enum eTCause { CallInProgress = 0, CallerNormal = 1, // NormalCallClearing CalledNormal = 2, // NormalCallClearing CallerDrop = 3, // Drop Call without ReleaseComplete message CalledDrop = 4, // Drop Call without ReleaseComplete message AuthReject = 5, // Reject due failed authentication InternalError = 6, // Due socket descriptor error ForceTermination = 20, // killed from ControlThread. TimeoutConnectMsg = 22, // Didn't get Connect message in 120sec TimeoutAlertingMsg = 23, // Didn't get Alerting message in 30 sec TimeoutMedia = 24, // Idle of MediaStream in 180 sec (for hung calls) NoRouteToDest = 25, // Unable to route call through dial-peers DestUnreach = 26, // Unable to establish TCP connect to destiantion. InvalidTPKTCaller = 27, // Invalid TPKT InvalidTPKTCalled = 28, // Invalid TPKT InvalidSetupMsg = 29, // Setup message without UUfield and etc. CallLoop = 30, // Double calls with equivalent CallID (for prevention loop) H245fail = 31, // H245 session fails (in 50 secs). ExceedRouteAttmpts = 32, // for preventing cyrcling routing SessionLimit = 33, // Max Session Time for user's account HungCall = 34, // Exceed time limit (after 3 hours call recognised like hung) RestrictedInPeer = 35, // Restricted prefix by an incoming dial-peer RestrictedTarget = 36, // Restricted by target gateway capacity RestrictedCalledN = 37, // Restricted by minimal CalledNumber digits TimeoutRlsCaller = 38, // Didn't get ReleaseComplete in answer TimeoutRlsCalled = 39, // Didn't get ReleaseComplete in answer TimeoutProceeding = 40 // Didn't get CallProceeding message in 30 sec }; TCallPool(const TGlobal & env, SignallingThread * ParenSigThread); virtual ~TCallPool(); bool NewMediaThread(unsigned CallRef); void StartMediaThread(unsigned CallRef); void StopMediaThread(unsigned CallRef); void Terminate(); bool BindRTPSockets(unsigned CallRef, WORD srcPort, WORD dstPort, WSocket::Address & inAddr, WSocket::Address & outAddr ); bool BindRTCPSockets(unsigned CallRef, WORD srcPort, WORD dstPort, WSocket::Address & inAddr, WSocket::Address & outAddr ); void SetControlChannel(unsigned CallRef, H245_TransportAddress & vAddr, bool FromCaller); void SetMediaChannel(unsigned CallRef, H245_TransportAddress & vAddr, bool FromCaller); void MediaThreadPrintOn(unsigned CallRef); bool IsMediaRunning(unsigned CallRef) ; void SetMediaRunning(unsigned CallRef, bool val) ; void SetMediaChannelOpened(unsigned CallRef, bool FromCaller); bool IsMediaChannelsOpened(unsigned CallRef); void SetfState(unsigned CallRef, FastStartStates State); FastStartStates GetfState(unsigned CallRef); void EstablishedConnectionCheck(unsigned CallRef); bool IsDetermined(unsigned CallRef); void DeterminedSet(unsigned CallRef, bool val = true); bool HasCapabilities(unsigned CallRef); bool HasFullCapabilities(unsigned CallRef) { return (OutCapability[CallRef] && InCapability[CallRef]) ;}; void NewH245Thread(TGlobal & AkaEnviron, TCallPool * vCallPool, unsigned CallRef, const H225_TransportAddress & CalledAddress, bool FromCaller); bool CheckTimeout(unsigned CallRef); void StopAcctCall(unsigned CallRef); void ClearCall(unsigned CallRef); SignallingThread * Parent; map OutCapability, InCapability, Tunneling; map BillRecID, StartTime, StopTime, RTCPcount, Attempts ; map IncBytes, OutBytes; map IncTC, OutTC; map InternTC; map Timeout, LastIncByte, LastOutByte; map CalledNumber, DestGW; map cStatesList; map H245ThreadList; map fStatesList; map CallIdent; map PFSe; // ProceedFastStart elements buffer map WasPFSe, HasDefferedAlert, ReadyToClose, MediaProxing; map SetupMsg, AlertMsg; map IncCDR, OutCDR; map H245ThreadID; map OutCalledSocket; map OutLocalAddr, OutAddr; map MediaThreadList; protected: const TGlobal & env; map Determined; }; #endif // _CALLTHREAD_H