1 //////////////////////////////////////////////////////////////////
3 // bookkeeping for RAS-Server in H.323 gatekeeper
5 // This work is published under the GNU Public License (GPL)
6 // see file COPYING for details.
7 // We also explicitely grant the right to link this code
8 // with the OpenH323 library.
10 //////////////////////////////////////////////////////////////////
13 #define RASTBL_H "@(#) $Id: RasTbl.h,v 1.116.2.1 2007/04/26 19:29:48 willamowius Exp $"
19 #include "singleton.h"
23 #include "pwlib_compat.h"
26 #if (_MSC_VER >= 1200)
27 #pragma warning( disable : 4786 ) // warning about too long debug symbol off
28 #pragma warning( disable : 4800 )
35 class GkDestAnalysisList;
37 class CallSignalSocket;
41 template <class> class H225SignalingMsg;
42 typedef H225SignalingMsg<H225_Setup_UUIE> SetupMsg;
44 // Template of smart pointer
45 // The class T must have Lock() & Unlock() methods
46 template<class T> class SmartPtr {
48 explicit SmartPtr(T *t = 0) : pt(t) { Inc(); }
49 SmartPtr(const SmartPtr<T> & p) : pt(p.pt) { Inc(); }
50 ~SmartPtr() { Dec(); }
51 operator bool() const { return pt != 0; }
52 T *operator->() const { return pt; }
54 bool operator==(const SmartPtr<T> & p) const { return pt == p.pt; }
55 bool operator!=(const SmartPtr<T> & p) const { return pt != p.pt; }
57 SmartPtr<T> &operator=(const SmartPtr<T> & p) {
59 Dec(), pt = p.pt, Inc();
64 void Inc() const { if (pt) pt->Lock(); }
65 void Dec() const { if (pt) pt->Unlock(); }
73 /** Construct internal/outer zone endpoint from the specified RAS message.
74 RRQ builds an internal zone endpoint, ARQ, ACF and LCF build outer zone
78 /// RRQ, ARQ, ACF or LCF that contains a description of the endpoint
79 const H225_RasMessage& ras,
80 /// permanent endpoint flag
81 bool permanent = false
84 virtual ~EndpointRec();
86 // public interface to access EndpointRec
87 H225_TransportAddress GetRasAddress() const;
88 H225_TransportAddress GetCallSignalAddress() const;
89 H225_EndpointIdentifier GetEndpointIdentifier() const;
90 H225_ArrayOf_AliasAddress GetAliases() const;
91 H225_EndpointType GetEndpointType() const;
92 int GetTimeToLive() const;
93 PIPSocket::Address GetNATIP() const;
94 CallSignalSocket *GetSocket();
96 int GetCallTypeOfNumber(bool called = true) const { return called ? m_calledTypeOfNumber : m_callingTypeOfNumber; }
97 int GetProxyType() const { return m_proxy; }
99 /** checks if the given aliases are prefixes of the aliases which are stored
100 for the endpoint in the registration table. #fullMatch# returns #TRUE# if
101 a full match is found.
102 @returns #TRUE# if a match is found
104 bool PrefixMatch_IncompleteAddress(const H225_ArrayOf_AliasAddress &aliases,
105 bool &fullMatch) const;
107 virtual void SetRasAddress(const H225_TransportAddress &);
108 virtual void SetCallSignalAddress(const H225_TransportAddress &);
109 virtual void SetEndpointIdentifier(const H225_EndpointIdentifier &);
110 virtual void SetTimeToLive(int);
111 virtual void SetAliases(const H225_ArrayOf_AliasAddress &);
112 virtual void SetEndpointType(const H225_EndpointType &);
114 virtual void Update(const H225_RasMessage & lightweightRRQ);
115 virtual bool IsGateway() const { return false; }
117 /** Find if one of the given aliases matches any alias for this endpoint.
120 true if the match has been found, false otherwise.
122 virtual bool CompareAlias(
123 /// aliases to be matched (one of them)
124 const H225_ArrayOf_AliasAddress* aliases
127 /** Find if one of the given aliases matches any alias for this endpoint
128 and return an index for the matching alias.
131 true if the match has been found, false otherwise.
133 virtual bool MatchAlias(
134 /// aliases to be matched (one of them)
135 const H225_ArrayOf_AliasAddress& aliases,
136 /// filled with an index into aliases for the matching alias (if found)
140 /** Load additional endpoint settings from the config file.
141 Derived classes should call LoadConfig method of their base class
142 at the beginning of the overriden LoadConfig.
145 True if the configuration has been updated successfully.
147 virtual bool LoadConfig();
149 virtual EndpointRec *Unregisterpreempt(int type);
150 virtual EndpointRec *Unregister();
151 virtual EndpointRec *Expired();
153 //virtual void BuildACF(H225_AdmissionConfirm &) const;
154 //virtual void BuildLCF(H225_LocationConfirm &) const;
156 virtual PString PrintOn(bool verbose) const;
158 void SetNAT(bool nat);
159 void SetNATAddress(const PIPSocket::Address &);
160 void SetSocket(CallSignalSocket *);
161 void SetSupportNAT(bool support);
162 void SetPriority(int priority) { m_registrationPriority = priority; };
163 void SetPreemption(bool support) { m_registrationPreemption = support; };
164 void SetAssignedGatekeeper(const H225_AlternateGK & gk) { m_assignedGatekeeper = gk; };
168 true if this is a permanent endpoint loaded from the config file entry.
170 bool IsPermanent() const;
172 bool IsUpdated(const PTime *) const;
173 bool IsFromParent() const;
174 bool IsNATed() const;
175 bool SupportNAT() const;
176 int Priority() const { return m_registrationPriority; }
177 bool HasNATSocket() const;
178 PTime GetUpdatedTime() const;
180 /** If this Endpoint would be register itself again with all the same data
181 * how would this RRQ would look like? May be implemented with a
182 * built-together-RRQ, but for the moment a stored RRQ.
184 H225_RasMessage GetCompleteRegistrationRequest() const;
187 void AddConnectedCall();
195 bool HasCallCreditCapabilities() const;
197 /** Append a call credit related service control descriptor to the array
198 of service control sessions, if the endpoint supports call credit
201 virtual void AddCallCreditServiceControl(
202 H225_ArrayOf_ServiceControlSession& sessions, /// array to add the service control descriptor to
203 const PString& amountStr, /// user's account balance amount string
204 int billingMode, /// user's account billing mode (-1 if not set)
205 long callDurationLimit /// call duration limit (-1 if not set)
209 True if the endpoint can handle at least one more concurrent call.
211 bool HasAvailableCapacity() const { return m_capacity == -1 || m_activeCall < m_capacity; }
213 // smart pointer for EndpointRec
214 typedef SmartPtr<EndpointRec> Ptr;
218 void SetEndpointRec(H225_RegistrationRequest &);
219 void SetEndpointRec(H225_AdmissionRequest &);
220 void SetEndpointRec(H225_AdmissionConfirm &);
221 void SetEndpointRec(H225_LocationConfirm &);
223 bool SendURQ(H225_UnregRequestReason::Choices, int preemption);
226 /// Load general endpoint settings from the config
227 void LoadEndpointConfig();
230 EndpointRec(const EndpointRec &);
231 EndpointRec & operator= (const EndpointRec &);
234 /**This field may disappear sometime when GetCompleteRegistrationRequest() can
235 * build its return value itself.
236 * @see GetCompleteRegistrationRequest()
238 H225_RasMessage m_RasMsg;
240 H225_TransportAddress m_rasAddress;
241 H225_TransportAddress m_callSignalAddress;
242 H225_EndpointIdentifier m_endpointIdentifier;
243 H225_ArrayOf_AliasAddress m_terminalAliases;
244 H225_EndpointType *m_terminalType;
245 int m_timeToLive; // seconds
247 int m_activeCall, m_connectedCall, m_totalCall;
248 int m_pollCount, m_usedCount;
249 mutable PMutex m_usedLock;
252 bool m_fromParent, m_nat, m_natsupport;
253 PIPSocket::Address m_natip;
254 CallSignalSocket *m_natsocket;
255 /// permanent (preconfigured) endpoint flag
257 /// can understand H.225 CallCreditServiceControl
258 bool m_hasCallCreditCapabilities;
259 /// session number for call credit service control session
260 int m_callCreditSession;
261 /// endpoint call capacity, -1 means no limit
263 int m_calledTypeOfNumber, m_callingTypeOfNumber;
266 /// Registration Priority Number
267 int m_registrationPriority;
268 /// Support Registration PreEmption
269 bool m_registrationPreemption;
271 /// Assigned Gatekeeper
272 H225_AlternateGK m_assignedGatekeeper;
275 typedef EndpointRec::Ptr endptr;
278 class GatewayRec : public EndpointRec {
280 typedef std::map<std::string, int>::iterator prefix_iterator;
281 typedef std::map<std::string, int>::const_iterator const_prefix_iterator;
283 GatewayRec(const H225_RasMessage & completeRAS, bool Permanent=false);
285 virtual void SetEndpointType(const H225_EndpointType &);
287 virtual void Update(const H225_RasMessage & lightweightRRQ);
288 virtual bool IsGateway() const { return true; }
290 /// Overiden from EndpointRec
291 virtual bool LoadConfig();
293 /** Find if at least one of the given aliases matches any prefix
297 Length (number of characters) of the match, 0 if no match has been
298 found and this is the default gateway, -1 if no match has been found
299 and this is not the default gateway.
301 virtual int PrefixMatch(
302 /// aliases to be matched (one of them)
303 const H225_ArrayOf_AliasAddress& aliases
306 /** Find if at least one of the given aliases matches any prefix
307 for this gateway and return an index of the matched alias.
310 Length (number of characters) of the match, 0 if no match has been
311 found and this is the default gateway, -1 if no match has been found
312 and this is not the default gateway.
314 virtual int PrefixMatch(
315 /// aliases to be matched (one of them)
316 const H225_ArrayOf_AliasAddress& aliases,
317 /// filled with an index of the matching alias (if found)
319 /// priority of matched prefix
323 //virtual void BuildLCF(H225_LocationConfirm &) const;
325 virtual PString PrintOn(bool verbose) const;
327 void AddPrefixes(const H225_ArrayOf_SupportedProtocols &);
328 void AddPrefixes(const PString &);
332 Priority for this gateway, when more than one gateway matches
335 int GetPriority() const { return priority; }
337 /// Set the priority for this gateway.
342 //void DumpPriorities() const;
345 /// Load gateway specific settings from the config
346 void LoadGatewayConfig();
349 GatewayRec(const GatewayRec&);
350 GatewayRec& operator=(const GatewayRec&);
353 std::map<std::string, int> Prefixes;
356 /// priority for this gateway (when more than one gw matches a dialed number)
361 class OuterZoneEPRec : public EndpointRec {
363 OuterZoneEPRec(const H225_RasMessage & completeRAS, const H225_EndpointIdentifier &);
365 virtual EndpointRec *Unregister() { return this; }
366 virtual EndpointRec *Expired() { return this; }
370 class OuterZoneGWRec : public GatewayRec {
372 OuterZoneGWRec(const H225_RasMessage & completeRAS, const H225_EndpointIdentifier &);
374 virtual EndpointRec *Unregister() { return this; }
375 virtual EndpointRec *Expired() { return this; }
379 class RegistrationTable : public Singleton<RegistrationTable> {
381 typedef std::list<EndpointRec *>::iterator iterator;
382 typedef std::list<EndpointRec *>::const_iterator const_iterator;
385 ~RegistrationTable();
387 void Initialize(GkDestAnalysisList & list) { m_destAnalysisList = &list; }
389 endptr InsertRec(H225_RasMessage & rrq, PIPSocket::Address = INADDR_ANY);
390 void RemoveByEndptr(const endptr & eptr);
391 void RemoveByEndpointId(const H225_EndpointIdentifier & endpointId);
393 endptr FindByEndpointId(const H225_EndpointIdentifier & endpointId) const;
394 endptr FindBySignalAdr(const H225_TransportAddress &, PIPSocket::Address = INADDR_ANY) const;
395 endptr FindOZEPBySignalAdr(const H225_TransportAddress &) const;
396 endptr FindByAliases(const H225_ArrayOf_AliasAddress & alias) const;
397 endptr FindEndpoint(const H225_ArrayOf_AliasAddress & alias, bool RoundRobin, bool SearchOuterZone = true);
399 const H225_ArrayOf_AliasAddress &aliases,
401 bool searchOuterZone,
402 std::list<Routing::Route> &routes
406 void CheckEndpoints();
408 void PrintAllRegistrations(USocket *client, BOOL verbose=FALSE);
409 void PrintAllCached(USocket *client, BOOL verbose=FALSE);
410 void PrintRemoved(USocket *client, BOOL verbose=FALSE);
412 PString PrintStatistics() const;
414 // void PrintOn( ostream &strm ) const;
416 /** Updates Prefix + Flags for all aliases */
419 PINDEX Size() const { return regSize; }
423 endptr InternalInsertEP(H225_RasMessage &);
424 endptr InternalInsertOZEP(H225_RasMessage &, H225_LocationConfirm &);
425 endptr InternalInsertOZEP(H225_RasMessage &, H225_AdmissionConfirm &);
427 void InternalPrint(USocket *, BOOL, std::list<EndpointRec *> *, PString &);
428 void InternalStatistics(const std::list<EndpointRec *> *, unsigned & s, unsigned & t, unsigned & g, unsigned & n) const;
430 void InternalRemove(iterator);
432 template<class F> endptr InternalFind(const F & FindObject) const
433 { return InternalFind(FindObject, &EndpointList); }
435 template<class F> endptr InternalFind(const F & FindObject, const std::list<EndpointRec *> *ListToBeFound) const
436 { // The function body must be put here,
437 // or the Stupid VC would fail to instantiate it
438 ReadLock lock(listLock);
439 const_iterator Iter(find_if(ListToBeFound->begin(), ListToBeFound->end(), FindObject));
440 return endptr((Iter != ListToBeFound->end()) ? *Iter : 0);
443 endptr InternalFindEP(const H225_ArrayOf_AliasAddress & alias, std::list<EndpointRec *> *ListToBeFound, bool roundrobin);
444 void InternalFindEP(const H225_ArrayOf_AliasAddress & alias, std::list<EndpointRec *> *ListToBeFound, bool roundrobin, std::list<Routing::Route> &routes);
446 void GenerateEndpointId(H225_EndpointIdentifier &);
447 void GenerateAlias(H225_ArrayOf_AliasAddress &, const H225_EndpointIdentifier &) const;
449 GkDestAnalysisList & getGkDestAnalysisList() { return *m_destAnalysisList; }
450 std::list<EndpointRec *> EndpointList;
451 std::list<EndpointRec *> OuterZoneList;
452 std::list<EndpointRec *> RemovedList;
454 mutable PReadWriteMutex listLock;
455 PMutex findmutex; // Endpoint Find Mutex
456 GkDestAnalysisList * m_destAnalysisList;
458 // counter to generate endpoint identifier
459 // this is NOT the count of endpoints!
461 PString endpointIdSuffix; // Suffix of the generated Endpoint IDs
464 RegistrationTable(const RegistrationTable &);
465 RegistrationTable& operator=(const RegistrationTable &);
469 template<class> class RasPDU;
471 // record of one active call
474 /// flag to overwrite proxy settings for the call
476 ProxyDetect, /// use global settings from the config
477 ProxyEnabled, /// force full proxy mode
478 ProxyDisabled /// disable full proxy mode
481 /// who disconnected the call
483 ReleasedByGatekeeper,
488 /// build a new call record from the received ARQ message
490 /// ARQ with call information
491 const RasPDU<H225_AdmissionRequest>& arq,
492 /// bandwidth occupied by the call
494 /// called party's aliases in a string form
495 const PString& destInfo,
496 /// override proxy mode global setting from the config
497 int proxyMode = ProxyDetect
500 /// build a new call record from the received Setup message
502 /// Q.931 Setup pdu with call information
504 /// H.225.0 Setup-UUIE pdu with call information
505 const H225_Setup_UUIE& setup,
506 /// force H.245 routed mode
508 /// called party's aliases in a string form
509 const PString& destInfo,
510 /// override proxy mode global setting from the config
511 int proxyMode = ProxyDetect
520 enum NATType { // who is nated?
525 citronNAT = 4 // caller with Citron NAT Technology?
528 PINDEX GetCallNumber() const
529 { return m_CallNumber; }
530 const H225_CallIdentifier & GetCallIdentifier() const
531 { return m_callIdentifier; }
532 const H225_ConferenceIdentifier & GetConferenceIdentifier() const
533 { return m_conferenceIdentifier; }
534 endptr GetCallingParty() const { return m_Calling; }
535 endptr GetCalledParty() const { return m_Called; }
536 endptr GetForwarder() const { return m_Forwarder; }
537 int GetBandwidth() const { return m_bandwidth; }
540 A bit mask with NAT flags for calling and called parties.
541 See #NATType enum# for more details.
543 int GetNATType() const { return m_nattype; }
545 /// filled with NAT IP of the calling party (if nat type is callingParty)
546 PIPSocket::Address& callingPartyNATIP,
547 /// filled with NAT IP of the called party (if nat type is calledParty)
548 PIPSocket::Address& calledPartyNATIP
552 Current proxy mode flag (see #ProxyMode enum#).
554 int GetProxyMode() const { return m_proxyMode; }
556 /// Override proxy mode global setting from the config
558 int mode /// proxy mode flag (see #ProxyMode enum#)
561 CallSignalSocket *GetCallSignalSocketCalled() { return m_calledSocket; }
562 CallSignalSocket *GetCallSignalSocketCalling() { return m_callingSocket; }
563 const H225_ArrayOf_CryptoH323Token & GetAccessTokens() const { return m_accessTokens; }
564 PString GetInboundRewriteId() const { return m_inbound_rewrite_id; }
565 PString GetOutboundRewriteId() const { return m_outbound_rewrite_id; }
567 void SetCallNumber(PINDEX i) { m_CallNumber = i; }
568 void SetCalling(const endptr & NewCalling);
569 void SetCalled(const endptr & NewCalled);
570 void SetForward(CallSignalSocket *, const H225_TransportAddress &, const endptr &, const PString &, const PString &);
571 void SetBandwidth(int bandwidth) { m_bandwidth = bandwidth; }
572 void SetSocket(CallSignalSocket *, CallSignalSocket *);
573 void SetCallSignalSocketCalling(CallSignalSocket* socket);
574 void SetCallSignalSocketCalled(CallSignalSocket* socket);
575 void SetToParent(bool toParent) { m_toParent = toParent; }
576 void SetAccessTokens(const H225_ArrayOf_CryptoH323Token & tokens) { m_accessTokens = tokens; }
577 void SetInboundRewriteId(PString id) { m_inbound_rewrite_id = id; }
578 void SetOutboundRewriteId(PString id) { m_outbound_rewrite_id = id; }
582 void Disconnect(bool = false); // Send Release Complete?
585 void SendReleaseComplete(const H225_CallTerminationCause * = 0);
586 void BuildDRQ(H225_DisengageRequest &, unsigned reason) const;
588 int CountEndpoints() const;
590 bool CompareCallId(const H225_CallIdentifier *CallId) const;
591 bool CompareCRV(WORD crv) const;
592 bool CompareCallNumber(PINDEX CallNumber) const;
593 bool CompareEndpoint(const endptr *) const;
594 bool CompareSigAdr(const H225_TransportAddress *adr) const;
596 bool IsUsed() const { return (m_usedCount != 0); }
599 true if the call has been connected - a Connect message
600 has been received in gk routed signalling or the call has been admitted
601 (ARQ->ACF) in direct signalling. Does not necessary mean
602 that the call is still in progress (may have been already disconnected).
604 bool IsConnected() const { return (m_connectTime != 0); }
606 bool IsH245Routed() const { return m_h245Routed; }
607 bool IsToParent() const { return m_toParent; }
608 bool IsForwarded() const { return m_forwarded; }
609 bool IsSocketAttached() const { return (m_callingSocket != 0); }
612 /// timestamp formatting string (empty for a default RFC822 format)
613 const PString& timestampFormat = PString()
615 PString PrintOn(bool verbose) const;
621 Q.931 ReleaseComplete cause code for the call.
622 0 if the disconnect cause could not be determined.
624 unsigned GetDisconnectCause() const;
626 /** Set Q.931 ReleaseComplete cause code associated with this call. */
627 void SetDisconnectCause(
631 /// @return Information about who disconnected the call (see #ReleaseSource enum#)
632 int GetReleaseSource() const;
634 /// Set information about who disconnected the call
635 void SetReleaseSource(
636 int releaseSentFrom /// see #ReleaseSource enum#
639 /** Set maximum duration limit (in seconds) for this call */
640 void SetDurationLimit(
641 long seconds /// duration limit to be set
645 Duration limit (in seconds) set for this call.
646 0 if call duration is not limited.
648 long GetDurationLimit() const;
650 /** This function can be used to determine, if the call has been
651 disconnected due to call duration limit excess.
654 true if the call duration limit has been exceeded, false otherwise.
656 bool IsDurationLimitExceeded() const;
659 Timestamp (number of seconds since 1st January 1970) for the call creation
660 (when this CallRec object has been instantiated).
662 time_t GetCreationTime() const;
665 Timestamp (number of seconds since 1st January 1970)
666 for the Setup message associated with this call. 0 if Setup
667 has not been yet received.
668 Meaningful only in GK routed mode.
670 time_t GetSetupTime() const;
672 /** Set timestamp for a Setup message associated with this call. */
674 time_t tm /// timestamp (seconds since 1st January 1970)
678 Timestamp (number of seconds since 1st January 1970)
679 for the Alerting message associated with this call. 0 if Alerting
680 has not been yet received.
681 Meaningful only in GK routed mode.
683 time_t GetAlertingTime() const;
685 /** Set timestamp for a Alerting message associated with this call. */
686 void SetAlertingTime(
687 time_t tm /// timestamp (seconds since 1st January 1970)
691 Timestamp (number of seconds since 1st January 1970)
692 for the Connect message associated with this call. 0 if Connect
693 has not been yet received. If GK is not in routed mode, this is
694 timestamp for ACF generated as a response to ARQ.
696 time_t GetConnectTime() const;
698 /** Set timestamp for a Connect (or ACF) message associated with this call. */
700 time_t tm /// timestamp (seconds since 1st January 1970)
704 Timestamp (number of seconds since 1st January 1970)
705 for the call disconnect event. 0 if call has not been yet disconnected
708 time_t GetDisconnectTime() const;
710 /** Set timestamp for a disconnect event for this call. */
711 void SetDisconnectTime(
712 time_t tm /// timestamp (seconds since 1st January 1970)
716 Timestamp for the most recent accounting update event logged for this call.
718 time_t GetLastAcctUpdateTime() const { return m_acctUpdateTime; }
720 /** Set timestamp for the most recent accounting update event logged
723 void SetLastAcctUpdateTime(
724 const time_t tm /// timestamp of the recent accounting update operation
727 m_acctUpdateTime = tm;
731 - a signalling channel associated with this call is not timed out
732 and the call should be disconnected (removed from CallTable);
733 - call duration limit has been exceeded
734 - call should be disconnected from other reason
737 true if call is timed out and should be disconnected, false otherwise.
740 /// point in time for timeouts to be measured relatively to
741 /// (made as a parameter for performance reasons)
746 Call duration in seconds. 0 for unconnected calls. Actual
747 duration for calls in progress.
749 long GetDuration() const;
752 Call total time in seconds. 0 for calls without disconnect.
754 long GetTotalCallDuration() const;
757 Call Post Dial Delay in seconds.
759 long GetPostDialDelay() const;
762 Call ring time in seconds. 0 for calls without Alerting.
764 long GetRingTime() const;
767 A string that identifies uniquelly this call for accounting
768 purposes. This string should be unique across subsequent GK
771 PString GetAcctSessionId() const { return m_acctSessionId; }
774 A string with ARQ.m_srcInfo for registered endpoints
775 and Setup.m_sourceAddress for unregistered endpoints.
776 The string has alias type appended (example: '772:dialedDigits')
777 and for forwarded calls contains alias of forwarding
778 after '=' (example: '772:dialedDigits=775:forward').
780 PString GetSrcInfo() const { return m_srcInfo; }
782 /** Set a new address for the calling party signalling channel.
784 void SetSrcSignalAddr(
785 const H225_TransportAddress & addr /// new signalling transport address
788 /** Set the unregistered calling party signalling channel as NATed.
790 void SetSrcNATed(PIPSocket::Address & natip);
792 /** Set a new address for the called party signalling channel.
794 void SetDestSignalAddr(
795 const H225_TransportAddress & addr /// new signalling transport address
798 /** Get IP and port for the calling party. It is a signal address
799 for registered endpoints and remote signalling socket address
800 for unregistered endpoints.
803 true if the address has been retrieved successfully, false otherwise.
805 bool GetSrcSignalAddr(
806 PIPSocket::Address& addr, /// will receive the IP address
807 WORD& port /// will receive the port number
810 H225_TransportAddress GetDestSignalAddr() const;
812 /** Get IP and port for the called party. It is a signal address
813 for registered endpoints and remote signalling socket address
814 for unregistered endpoints.
817 true if the address has been retrieved successfully, false otherwise.
819 bool GetDestSignalAddr(
820 PIPSocket::Address& addr, /// will receive the IP address
821 WORD& port /// will receive the port number
825 A string with ARQ.m_destinationInfo or ARQ.m_destCallSignalAddress
826 or "unknown" for registered endpoints
827 and Setup.m_destinationAddress or called endpoint IP address
828 for unregistered endpoints.
829 The string has alias type appended (example: '772:dialedDigits')
830 and for forwarded calls contains alias of forwarding
831 after '=' (example: '772:dialedDigits=775:forward').
833 PString GetDestInfo() const { return m_destInfo; }
836 Calling party's aliases, as presented in ARQ or Setup messages.
837 This does not change during the call.
839 const H225_ArrayOf_AliasAddress& GetSourceAddress() const
840 { return m_sourceAddress; }
843 Called party's aliases, as presented in ARQ or Setup messages.
844 This does not change during the call now, but should be fixed
845 to handle gatekeeper call forwarding properly.
847 const H225_ArrayOf_AliasAddress& GetDestinationAddress() const
848 { return m_destinationAddress; }
851 Calling party's number or an empty string, if the number has not been
854 PString GetCallingStationId();
856 /// Set calling party's number
857 void SetCallingStationId(
858 const PString& id /// Calling-Station-Id
862 Called party's number or an empty string, if the number has not been
865 PString GetCalledStationId();
867 /// Set call linkage This the party to be charged for the call.
869 const PString& id /// Calling-Station-Id (to be charged)
873 Call party to be charged for the call.
875 PString GetCallLinkage()const { return m_callLinkage; };
878 /// Set calling party's number
879 void SetCalledStationId(
880 const PString& id /// Called-Station-Id
884 Called party's number before rewrite or an empty string,
885 if the number has not been yet determined.
887 PString GetDialedNumber();
889 /// Set dialed number
890 void SetDialedNumber(
891 const PString& number /// Dialed-Number
895 Fixed destination address for the call (NULL if not set).
897 H225_AliasAddress* GetRouteToAlias() const;
899 /// Set fixed destination address for the call
900 void SetRouteToAlias(
901 const H225_AliasAddress& alias /// alias to set
904 // smart pointer for CallRec
905 typedef SmartPtr<CallRec> Ptr;
907 /// update IRR timers
908 void Update(const H225_InfoRequestResponse & irr);
911 const std::list<Routing::Route> &routes
913 const std::list<Routing::Route> &GetNewRoutes() const { return m_newRoutes; }
914 const std::list<Routing::Route> &GetFailedRoutes() const { return m_failedRoutes; }
915 bool MoveToNextRoute();
917 bool IsCallInProgress() const;
918 void SetCallInProgress();
920 bool IsH245ResponseReceived() const;
921 void SetH245ResponseReceived();
923 bool IsFastStartResponseReceived() const;
924 void SetFastStartResponseReceived();
926 bool SingleFailoverCDR() const;
927 int GetNoCallAttempts() const;
928 int GetNoRemainingRoutes() const;
929 bool DisableRetryChecks() const;
931 void SetCodec(const PString &codec);
932 PString GetCodec() const;
934 void SetMediaOriginatingIp(const PIPSocket::Address &addr);
935 bool GetMediaOriginatingIp(PIPSocket::Address &addr) const;
937 void SetRADIUSClass(const PBYTEArray &bytes);
938 void SetRADIUSClass(void * bytes, PINDEX len);
939 PBYTEArray GetRADIUSClass() const;
943 void InternalSetEP(endptr &, const endptr &);
945 CallRec(const CallRec & Other);
946 CallRec & operator= (const CallRec & other);
949 /// internal call number generated by the gatekeeper
951 /// H.323 Call Identifier (identifies this particular call leg)
952 H225_CallIdentifier m_callIdentifier;
953 /// H.323 Conference Identifier
954 H225_ConferenceIdentifier m_conferenceIdentifier;
955 /// Call Reference Value for the call
957 /// EndpointRec for the calling party (if it is a registered endpoint)
958 /// NOTE: it does not change during CallRec lifetime
960 /// EndpointRec for the called party (if it is a registered endpoint)
961 /// NOTE: it can change during CallRec lifetime
963 /// aliases identifying a calling party (as presented in ARQ or Setup)
964 H225_ArrayOf_AliasAddress m_sourceAddress;
965 /// aliases identifying a called party (as presented in ARQ or Setup)
966 H225_ArrayOf_AliasAddress m_destinationAddress;
967 /// calling party aliases in a string form
969 /// called party aliases in a string form
971 /// bandwidth occupied by this call (as declared in ARQ)
974 PString m_callerAddr, m_callerId;
975 PString m_calleeAddr, m_calleeId;
976 // rewrite id for inbound leg of call
977 PString m_inbound_rewrite_id;
978 // rewrite id for outbound leg of call
979 PString m_outbound_rewrite_id;
981 /// current timeout (or duration limit) for the call
983 /// timestamp for call timeout measuring
985 /// timestamp (seconds since 1st January, 1970) for the call creation
986 /// (triggered by ARQ or Setup)
987 time_t m_creationTime;
988 /// timestamp (seconds since 1st January, 1970) for a Setup message reception
990 /// timestamp (seconds since 1st January, 1970) for a Alerting message reception
991 time_t m_alertingTime;
992 /// timestamp (seconds since 1st January, 1970) for a Connect (routed mode)
993 /// or ARQ/ACF (direct mode) message reception
994 time_t m_connectTime;
995 /// timestamp (seconds since 1st January, 1970) for the call disconnect
996 time_t m_disconnectTime;
997 /// timestamp for the most recent accounting update event logged for this call
998 time_t m_acctUpdateTime;
999 /// duration limit (seconds) for this call, 0 means no limit
1000 long m_durationLimit;
1001 /// Q.931 release complete cause code
1002 unsigned m_disconnectCause;
1003 /// who disconnected the call (see #RelaseSource enum#)
1004 int m_releaseSource;
1005 /// unique accounting session id associated with this call
1006 PString m_acctSessionId;
1007 /// signalling transport address of the calling party
1008 H225_TransportAddress m_srcSignalAddress;
1009 /// signalling transport address of the called party
1010 H225_TransportAddress m_destSignalAddress;
1011 /// calling party's number
1012 PString m_callingStationId;
1013 /// called party's number
1014 PString m_calledStationId;
1015 /// party to be charged for the call
1016 PString m_callLinkage;
1017 /// dialed number (called party's number before rewrite)
1018 PString m_dialedNumber;
1019 /// fixed destination alias
1020 H225_AliasAddress* m_routeToAlias;
1022 CallSignalSocket *m_callingSocket, *m_calledSocket;
1025 mutable PTimedMutex m_usedLock, m_sockLock;
1028 /// unregistered caller NAT'd
1030 PIPSocket::Address m_srcunregNATAddress;
1033 /// the call is routed to this gatekeeper's parent gatekeeper
1038 /// enable/disable proxy mode (override global settings from the config)
1041 H225_ArrayOf_CryptoH323Token m_accessTokens;
1044 long m_irrFrequency;
1046 time_t m_irrCallerTimer;
1047 time_t m_irrCalleeTimer;
1049 std::list<Routing::Route> m_failedRoutes;
1050 std::list<Routing::Route> m_newRoutes;
1051 bool m_callInProgress;
1052 bool m_h245ResponseReceived;
1053 bool m_fastStartResponseReceived;
1054 bool m_singleFailoverCDR;
1057 PIPSocket::Address m_mediaOriginatingIp;
1058 PBYTEArray m_radiusClass;
1061 typedef CallRec::Ptr callptr;
1064 class CallTable : public Singleton<CallTable>
1067 typedef std::list<CallRec *>::iterator iterator;
1068 typedef std::list<CallRec *>::const_iterator const_iterator;
1073 void Insert(CallRec * NewRec);
1075 // bandwidth management
1076 void SetTotalBandwidth(int bw);
1077 bool GetAdmission(int bw);
1078 bool GetAdmission(int bw, const callptr &);
1079 int GetAvailableBW() const { return m_capacity; }
1081 callptr FindCallRec(const H225_CallIdentifier & CallId) const;
1082 callptr FindCallRec(const H225_CallReferenceValue & CallRef) const;
1083 callptr FindCallRec(PINDEX CallNumber) const;
1084 callptr FindCallRec(const endptr &) const;
1085 callptr FindBySignalAdr(const H225_TransportAddress & SignalAdr) const;
1089 RasServer* rassrv // to avoid call RasServer::Instance every second
1092 void RemoveCall(const H225_DisengageRequest & obj_drq, const endptr &);
1093 void RemoveCall(const callptr &);
1094 void RemoveFailedLeg(const callptr &);
1096 void PrintCurrentCalls(USocket *client, BOOL verbose=FALSE) const;
1097 PString PrintStatistics() const;
1099 void AddForwardedCall(const callptr &);
1100 endptr IsForwardedCall(const callptr &);
1104 PINDEX Size() const { return m_activeCall; }
1107 Timeout value for a signalling channel to be opened after ACF
1108 and for an Alerting message to be received after signalling start.
1109 The value is expressed in milliseconds.
1111 long GetSignalTimeout() const { return m_signalTimeout; }
1114 Timeout value for Connect message to be received after a call entered
1115 the Alerting state. The value is expressed in milliseconds.
1117 long GetAlertingTimeout() const { return m_alertingTimeout; }
1120 Default call duration limit value (seconds).
1122 long GetDefaultDurationLimit() const { return m_defaultDurationLimit; }
1124 /// @return True to log accounting for each call leg
1125 bool SingleFailoverCDR() const { return m_singleFailoverCDR; }
1128 template<class F> callptr InternalFind(const F & FindObject) const
1130 ReadLock lock(listLock);
1131 const_iterator Iter(find_if(CallList.begin(), CallList.end(), FindObject));
1132 return callptr((Iter != CallList.end()) ? *Iter : 0);
1135 bool InternalRemovePtr(CallRec *call);
1136 void InternalRemove(const H225_CallIdentifier & CallId);
1137 void InternalRemove(WORD CallRef);
1138 void InternalRemove(iterator);
1139 void InternalRemoveFailedLeg(iterator);
1141 void InternalStatistics(unsigned & n, unsigned & act, unsigned & nb, unsigned & np, PString & msg, BOOL verbose) const;
1143 std::list<CallRec *> CallList;
1144 std::list<CallRec *> RemovedList;
1149 PINDEX m_CallNumber;
1150 mutable PReadWriteMutex listLock;
1155 unsigned m_CallCount, m_successCall, m_neighborCall, m_parentCall, m_activeCall;
1157 /// timeout for a Connect message to be received
1158 /// and for a signalling channel to be opened after ACF/ARQ
1159 /// (0 if GK is not in routed mode)
1160 long m_signalTimeout;
1161 /// timeout for a Connect message to be received after getting an Alerting message
1162 long m_alertingTimeout;
1163 /// default call duration limit read from the config
1164 long m_defaultDurationLimit;
1165 /// default interval (seconds) for accounting updates to be logged
1166 long m_acctUpdateInterval;
1167 /// timestamp formatting string for CDRs
1168 PString m_timestampFormat;
1169 /// flag to trigger per call leg accounting
1170 bool m_singleFailoverCDR;
1172 CallTable(const CallTable &);
1173 CallTable& operator==(const CallTable &);
1176 // inline functions of EndpointRec
1177 inline H225_TransportAddress EndpointRec::GetRasAddress() const
1179 PWaitAndSignal lock(m_usedLock);
1180 return m_rasAddress;
1183 inline void EndpointRec::SetRasAddress(const H225_TransportAddress & addr)
1185 PWaitAndSignal lock(m_usedLock);
1186 m_rasAddress = addr;
1189 inline void EndpointRec::SetCallSignalAddress(const H225_TransportAddress & addr)
1191 PWaitAndSignal lock(m_usedLock);
1192 m_callSignalAddress = addr;
1195 inline H225_TransportAddress EndpointRec::GetCallSignalAddress() const
1197 PWaitAndSignal lock(m_usedLock);
1198 return m_callSignalAddress;
1201 inline H225_EndpointIdentifier EndpointRec::GetEndpointIdentifier() const
1203 PWaitAndSignal lock(m_usedLock);
1204 return m_endpointIdentifier;
1207 inline int EndpointRec::GetTimeToLive() const
1209 return m_timeToLive;
1212 inline H225_ArrayOf_AliasAddress EndpointRec::GetAliases() const
1214 PWaitAndSignal lock(m_usedLock);
1215 return m_terminalAliases;
1218 inline H225_EndpointType EndpointRec::GetEndpointType() const
1220 PWaitAndSignal lock(m_usedLock);
1221 return *m_terminalType;
1224 inline void EndpointRec::SetNAT(bool nat)
1229 inline void EndpointRec::SetSupportNAT(bool support)
1231 m_natsupport = support;
1234 inline bool EndpointRec::IsNATed() const
1239 inline bool EndpointRec::SupportNAT() const
1241 return m_natsupport;
1244 inline PIPSocket::Address EndpointRec::GetNATIP() const
1246 PWaitAndSignal lock(m_usedLock);
1250 inline CallSignalSocket *EndpointRec::GetSocket()
1252 PWaitAndSignal lock(m_usedLock);
1253 CallSignalSocket *socket = m_natsocket;
1258 inline bool EndpointRec::IsPermanent() const
1263 inline bool EndpointRec::IsUsed() const
1265 PWaitAndSignal lock(m_usedLock);
1266 return (m_activeCall > 0 || m_usedCount > 0);
1269 inline bool EndpointRec::IsUpdated(const PTime *now) const
1271 PWaitAndSignal lock(m_usedLock);
1272 return (!m_timeToLive || (*now - m_updatedTime).GetSeconds() < m_timeToLive);
1275 inline bool EndpointRec::IsFromParent() const
1277 return m_fromParent;
1280 inline bool EndpointRec::HasNATSocket() const
1285 inline PTime EndpointRec::GetUpdatedTime() const
1287 PWaitAndSignal lock(m_usedLock);
1288 return m_updatedTime;
1291 inline H225_RasMessage EndpointRec::GetCompleteRegistrationRequest() const
1293 PWaitAndSignal lock(m_usedLock);
1297 inline bool EndpointRec::HasCallCreditCapabilities() const
1299 return m_hasCallCreditCapabilities;
1302 inline void EndpointRec::AddCall()
1304 PWaitAndSignal lock(m_usedLock);
1305 ++m_activeCall, ++m_totalCall;
1308 inline void EndpointRec::AddConnectedCall()
1310 PWaitAndSignal lock(m_usedLock);
1314 inline void EndpointRec::RemoveCall()
1316 PWaitAndSignal lock(m_usedLock);
1320 inline void EndpointRec::Lock()
1322 PWaitAndSignal lock(m_usedLock);
1326 inline void EndpointRec::Unlock()
1328 PWaitAndSignal lock(m_usedLock);
1332 // inline functions of CallRec
1333 inline void CallRec::Lock()
1335 PWaitAndSignal lock(m_usedLock);
1339 inline void CallRec::Unlock()
1341 PWaitAndSignal lock(m_usedLock);
1345 inline bool CallRec::CompareCallId(const H225_CallIdentifier *CallId) const
1347 return (m_callIdentifier == *CallId);
1350 inline bool CallRec::CompareCRV(WORD crv) const
1352 return m_crv == (crv & 0x7fffu);
1355 inline bool CallRec::CompareCallNumber(PINDEX CallNumber) const
1357 return (m_CallNumber == CallNumber);
1360 inline bool CallRec::CompareEndpoint(const endptr *ep) const
1362 return (m_Calling && m_Calling == *ep) || (m_Called && m_Called == *ep);
1365 inline bool CallRec::CompareSigAdr(const H225_TransportAddress *adr) const
1367 return (m_Calling && m_Calling->GetCallSignalAddress() == *adr) ||
1368 (m_Called && m_Called->GetCallSignalAddress() == *adr);
1371 inline long CallRec::GetDurationLimit() const
1373 return m_durationLimit;
1376 inline time_t CallRec::GetCreationTime() const
1378 return m_creationTime;
1381 inline time_t CallRec::GetSetupTime() const
1386 inline time_t CallRec::GetAlertingTime() const
1388 return m_alertingTime;
1391 inline time_t CallRec::GetConnectTime() const
1393 return m_connectTime;
1396 inline time_t CallRec::GetDisconnectTime() const
1398 return m_disconnectTime;
1401 inline unsigned CallRec::GetDisconnectCause() const
1403 return m_disconnectCause;
1406 inline void CallRec::SetDisconnectCause( unsigned causeCode )
1408 // set the cause only if it has not been already set
1409 if( m_disconnectCause == 0 )
1410 m_disconnectCause = causeCode;
1413 inline bool CallRec::IsTimeout(const time_t now) const
1415 bool result = (m_timeout > 0) && (now >= m_timer) && ((now - m_timer) >= m_timeout);
1416 if (m_irrCheck && (m_irrFrequency > 0)) {
1418 result |= (now >= m_irrCallerTimer) && ((now - m_irrCallerTimer) >= 2 * m_irrFrequency);
1420 result |= (now >= m_irrCalleeTimer) && ((now - m_irrCalleeTimer) >= 2 * m_irrFrequency);