OSDN Git Service

Fix no pic
[uclinux-h8/uClinux-dist.git] / user / gnugk / RasTbl.h
1 //////////////////////////////////////////////////////////////////
2 //
3 // bookkeeping for RAS-Server in H.323 gatekeeper
4 //
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.
9 //
10 //////////////////////////////////////////////////////////////////
11
12 #ifndef RASTBL_H
13 #define RASTBL_H "@(#) $Id: RasTbl.h,v 1.116.2.1 2007/04/26 19:29:48 willamowius Exp $"
14
15 #include <list>
16 #include <vector>
17 #include <string>
18 #include "rwlock.h"
19 #include "singleton.h"
20 #include "h225.h"
21 #include "sigmsg.h"
22 #include "h323util.h"
23 #include "pwlib_compat.h"
24
25
26 #if (_MSC_VER >= 1200)
27 #pragma warning( disable : 4786 ) // warning about too long debug symbol off
28 #pragma warning( disable : 4800 )
29 #endif
30
31 namespace Routing {
32         struct Route;
33 }
34
35 class GkDestAnalysisList;
36 class USocket;
37 class CallSignalSocket;
38 class RasServer;
39 class Q931;
40 class SignalingMsg;
41 template <class> class H225SignalingMsg;
42 typedef H225SignalingMsg<H225_Setup_UUIE> SetupMsg;
43
44 // Template of smart pointer
45 // The class T must have Lock() & Unlock() methods
46 template<class T> class SmartPtr {
47 public:
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; }
53
54         bool operator==(const SmartPtr<T> & p) const { return pt == p.pt; }
55         bool operator!=(const SmartPtr<T> & p) const { return pt != p.pt; }
56
57         SmartPtr<T> &operator=(const SmartPtr<T> & p) {
58                 if (pt != p.pt)
59                         Dec(), pt = p.pt, Inc();
60                 return *this;
61         }
62
63 private:
64         void Inc() const { if (pt) pt->Lock(); }
65         void Dec() const { if (pt) pt->Unlock(); }
66         T &operator*();
67         T *pt;
68 };
69
70 class EndpointRec
71 {
72 public:
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
75                 endpoints.
76         */
77         EndpointRec(
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
82                 );
83
84         virtual ~EndpointRec();
85
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();
95
96         int GetCallTypeOfNumber(bool called = true) const { return called ? m_calledTypeOfNumber : m_callingTypeOfNumber; }
97         int GetProxyType() const { return m_proxy; }
98
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
103          */
104     bool PrefixMatch_IncompleteAddress(const H225_ArrayOf_AliasAddress &aliases,
105                                         bool &fullMatch) const;
106
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 &);
113
114         virtual void Update(const H225_RasMessage & lightweightRRQ);
115         virtual bool IsGateway() const { return false; }
116
117         /** Find if one of the given aliases matches any alias for this endpoint.
118
119                 @return
120                 true if the match has been found, false otherwise.
121         */
122         virtual bool CompareAlias(
123                 /// aliases to be matched (one of them)
124                 const H225_ArrayOf_AliasAddress* aliases
125                 ) const;
126
127         /** Find if one of the given aliases matches any alias for this endpoint
128                 and return an index for the matching alias.
129
130                 @return
131                 true if the match has been found, false otherwise.
132         */
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)
137                 int& matchedalias
138                 ) const;
139
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.
143                 
144             @return
145                 True if the configuration has been updated successfully.        
146         */
147         virtual bool LoadConfig();
148
149         virtual EndpointRec *Unregisterpreempt(int type);
150         virtual EndpointRec *Unregister();
151         virtual EndpointRec *Expired();
152
153         //virtual void BuildACF(H225_AdmissionConfirm &) const;
154         //virtual void BuildLCF(H225_LocationConfirm &) const;
155
156         virtual PString PrintOn(bool verbose) const;
157
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; };
165
166
167         /** @return
168                 true if this is a permanent endpoint loaded from the config file entry.
169         */
170         bool IsPermanent() const;
171         bool IsUsed() 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;
179
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.
183          */
184         H225_RasMessage GetCompleteRegistrationRequest() const;
185
186         void AddCall();
187         void AddConnectedCall();
188         void RemoveCall();
189
190         void Lock();
191         void Unlock();
192
193         bool SendIRQ();
194
195         bool HasCallCreditCapabilities() const;
196         
197         /** Append a call credit related service control descriptor to the array
198             of service control sessions, if the endpoint supports call credit 
199             capabilities.
200         */
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)
206                 );
207
208         /** @return
209             True if the endpoint can handle at least one more concurrent call.
210         */
211         bool HasAvailableCapacity() const { return m_capacity == -1 || m_activeCall < m_capacity; }
212         
213         // smart pointer for EndpointRec
214         typedef SmartPtr<EndpointRec> Ptr;
215
216 protected:
217
218         void SetEndpointRec(H225_RegistrationRequest &);
219         void SetEndpointRec(H225_AdmissionRequest &);
220         void SetEndpointRec(H225_AdmissionConfirm &);
221         void SetEndpointRec(H225_LocationConfirm &);
222
223         bool SendURQ(H225_UnregRequestReason::Choices, int preemption);
224
225 private:
226         /// Load general endpoint settings from the config
227         void LoadEndpointConfig();
228
229         EndpointRec();
230         EndpointRec(const EndpointRec &);
231         EndpointRec & operator= (const EndpointRec &);
232         
233 protected:
234         /**This field may disappear sometime when GetCompleteRegistrationRequest() can
235          * build its return value itself.
236          * @see GetCompleteRegistrationRequest()
237          */
238         H225_RasMessage m_RasMsg;
239
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
246
247         int m_activeCall, m_connectedCall, m_totalCall;
248         int m_pollCount, m_usedCount;
249         mutable PMutex m_usedLock;
250
251         PTime m_updatedTime;
252         bool m_fromParent, m_nat, m_natsupport;
253         PIPSocket::Address m_natip;
254         CallSignalSocket *m_natsocket;
255         /// permanent (preconfigured) endpoint flag
256         bool m_permanent;
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
262         int m_capacity;
263         int m_calledTypeOfNumber, m_callingTypeOfNumber;
264         /// Proxy Type
265         int m_proxy;
266         /// Registration Priority Number
267         int m_registrationPriority;
268         /// Support Registration PreEmption
269         bool m_registrationPreemption;
270
271     /// Assigned Gatekeeper
272         H225_AlternateGK m_assignedGatekeeper;
273 };
274
275 typedef EndpointRec::Ptr endptr;
276
277
278 class GatewayRec : public EndpointRec {
279 public:
280         typedef std::map<std::string, int>::iterator prefix_iterator;
281         typedef std::map<std::string, int>::const_iterator const_prefix_iterator;
282
283         GatewayRec(const H225_RasMessage & completeRAS, bool Permanent=false);
284
285         virtual void SetEndpointType(const H225_EndpointType &);
286
287         virtual void Update(const H225_RasMessage & lightweightRRQ);
288         virtual bool IsGateway() const { return true; }
289
290         /// Overiden from EndpointRec
291         virtual bool LoadConfig();
292
293         /** Find if at least one of the given aliases matches any prefix
294                 for this gateway.
295
296                 @return
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.
300         */
301         virtual int PrefixMatch(
302                 /// aliases to be matched (one of them)
303                 const H225_ArrayOf_AliasAddress& aliases
304                 ) const;
305
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.
308
309                 @return
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.
313         */
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)
318                 int& matchedalias,
319                 /// priority of matched prefix
320                 int& priority
321                 ) const;
322
323         //virtual void BuildLCF(H225_LocationConfirm &) const;
324
325         virtual PString PrintOn(bool verbose) const;
326
327         void AddPrefixes(const H225_ArrayOf_SupportedProtocols &);
328         void AddPrefixes(const PString &);
329         void SortPrefixes();
330
331         /** @return
332             Priority for this gateway, when more than one gateway matches
333             a dialed number.
334         */
335         int GetPriority() const { return priority; }
336         
337         /// Set the priority for this gateway.
338         void SetPriority(
339                 int newPriority
340                 );
341
342         //void DumpPriorities() const;
343
344 private:
345         /// Load gateway specific settings from the config
346         void LoadGatewayConfig();
347         
348         GatewayRec();
349         GatewayRec(const GatewayRec&);
350         GatewayRec& operator=(const GatewayRec&);
351
352 protected:
353         std::map<std::string, int> Prefixes;
354
355         bool defaultGW;
356         /// priority for this gateway (when more than one gw matches a dialed number)
357         int priority;
358 };
359
360
361 class OuterZoneEPRec : public EndpointRec {
362 public:
363         OuterZoneEPRec(const H225_RasMessage & completeRAS, const H225_EndpointIdentifier &);
364
365         virtual EndpointRec *Unregister() { return this; }
366         virtual EndpointRec *Expired() { return this; }
367 };
368
369
370 class OuterZoneGWRec : public GatewayRec {
371 public:
372         OuterZoneGWRec(const H225_RasMessage & completeRAS, const H225_EndpointIdentifier &);
373
374         virtual EndpointRec *Unregister() { return this; }
375         virtual EndpointRec *Expired() { return this; }
376 };
377
378
379 class RegistrationTable : public Singleton<RegistrationTable> {
380 public:
381         typedef std::list<EndpointRec *>::iterator iterator;
382         typedef std::list<EndpointRec *>::const_iterator const_iterator;
383
384         RegistrationTable();
385         ~RegistrationTable();
386
387         void Initialize(GkDestAnalysisList & list) { m_destAnalysisList = &list; }
388
389         endptr InsertRec(H225_RasMessage & rrq, PIPSocket::Address = INADDR_ANY);
390         void RemoveByEndptr(const endptr & eptr);
391         void RemoveByEndpointId(const H225_EndpointIdentifier & endpointId);
392
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);
398         void FindEndpoint(
399                 const H225_ArrayOf_AliasAddress &aliases,
400                 bool roundRobin,
401                 bool searchOuterZone,
402                 std::list<Routing::Route> &routes
403                 );
404
405         void ClearTable();
406         void CheckEndpoints();
407
408         void PrintAllRegistrations(USocket *client, BOOL verbose=FALSE);
409         void PrintAllCached(USocket *client, BOOL verbose=FALSE);
410         void PrintRemoved(USocket *client, BOOL verbose=FALSE);
411
412         PString PrintStatistics() const;
413
414 //      void PrintOn( ostream &strm ) const;
415
416         /** Updates Prefix + Flags for all aliases */
417         void LoadConfig();
418
419         PINDEX Size() const { return regSize; }
420
421 private:
422
423         endptr InternalInsertEP(H225_RasMessage &);
424         endptr InternalInsertOZEP(H225_RasMessage &, H225_LocationConfirm &);
425         endptr InternalInsertOZEP(H225_RasMessage &, H225_AdmissionConfirm &);
426
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;
429
430         void InternalRemove(iterator);
431
432         template<class F> endptr InternalFind(const F & FindObject) const
433         { return InternalFind(FindObject, &EndpointList); }
434
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);
441         }
442
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);
445
446         void GenerateEndpointId(H225_EndpointIdentifier &);
447         void GenerateAlias(H225_ArrayOf_AliasAddress &, const H225_EndpointIdentifier &) const;
448
449         GkDestAnalysisList & getGkDestAnalysisList() { return *m_destAnalysisList; }
450         std::list<EndpointRec *> EndpointList;
451         std::list<EndpointRec *> OuterZoneList;
452         std::list<EndpointRec *> RemovedList;
453         int regSize;
454         mutable PReadWriteMutex listLock;
455         PMutex findmutex;          // Endpoint Find Mutex
456         GkDestAnalysisList * m_destAnalysisList;
457
458         // counter to generate endpoint identifier
459         // this is NOT the count of endpoints!
460         int recCnt, ozCnt;
461         PString endpointIdSuffix; // Suffix of the generated Endpoint IDs
462
463         // not assignable
464         RegistrationTable(const RegistrationTable &);
465         RegistrationTable& operator=(const RegistrationTable &);
466 };
467
468
469 template<class> class RasPDU;
470
471 // record of one active call
472 class CallRec {
473 public:
474         /// flag to overwrite proxy settings for the call
475         enum ProxyMode {
476                 ProxyDetect, /// use global settings from the config
477                 ProxyEnabled, /// force full proxy mode
478                 ProxyDisabled /// disable full proxy mode
479         };
480
481         /// who disconnected the call
482         enum ReleaseSource {
483                 ReleasedByGatekeeper,
484                 ReleasedByCaller,
485                 ReleasedByCallee
486         };
487
488         /// build a new call record from the received ARQ message
489         CallRec(
490                 /// ARQ with call information
491                 const RasPDU<H225_AdmissionRequest>& arq,
492                 /// bandwidth occupied by the call
493                 int bandwidth,
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
498                 );
499
500         /// build a new call record from the received Setup message
501         CallRec(
502                 /// Q.931 Setup pdu with call information
503                 const Q931& q931pdu,
504                 /// H.225.0 Setup-UUIE pdu with call information
505                 const H225_Setup_UUIE& setup,
506                 /// force H.245 routed mode
507                 bool routeH245,
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
512                 );
513         
514         CallRec(
515                 CallRec *oldCall
516                 );
517                 
518         virtual ~CallRec();
519
520         enum NATType { // who is nated?
521                 none = 0,
522                 callingParty = 1,
523                 calledParty = 2,
524                 both = 3,
525                 citronNAT = 4  // caller with Citron NAT Technology?
526         };
527
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; }
538
539         /** @return
540             A bit mask with NAT flags for calling and called parties. 
541             See #NATType enum# for more details.
542         */
543         int GetNATType() const { return m_nattype; }
544         int GetNATType(
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
549                 ) const;
550
551         /** @return
552             Current proxy mode flag (see #ProxyMode enum#).
553         */
554         int GetProxyMode() const { return m_proxyMode; }
555         
556         /// Override proxy mode global setting from the config
557         void SetProxyMode(
558                 int mode /// proxy mode flag (see #ProxyMode enum#)
559                 );
560
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; }
566
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; }
579
580         void SetConnected();
581
582         void Disconnect(bool = false); // Send Release Complete?
583         void RemoveAll();
584         void RemoveSocket();
585         void SendReleaseComplete(const H225_CallTerminationCause * = 0);
586         void BuildDRQ(H225_DisengageRequest &, unsigned reason) const;
587
588         int CountEndpoints() const;
589
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;
595
596         bool IsUsed() const { return (m_usedCount != 0); }
597
598         /** @return
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).
603         */
604         bool IsConnected() const { return (m_connectTime != 0); }
605
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); }
610
611         PString GenerateCDR(
612                 /// timestamp formatting string (empty for a default RFC822 format)
613                 const PString& timestampFormat = PString()
614                 ) const;
615         PString PrintOn(bool verbose) const;
616
617         void Lock();
618         void Unlock();
619
620         /** @return
621                 Q.931 ReleaseComplete cause code for the call.
622                 0 if the disconnect cause could not be determined.
623         */
624         unsigned GetDisconnectCause() const;
625
626         /** Set Q.931 ReleaseComplete cause code associated with this call. */
627         void SetDisconnectCause(
628                 unsigned causeCode
629                 );
630
631         /// @return     Information about who disconnected the call (see #ReleaseSource enum#)
632         int GetReleaseSource() const;
633
634         /// Set information about who disconnected the call
635         void SetReleaseSource(
636                 int releaseSentFrom /// see #ReleaseSource enum#
637                 );
638
639         /** Set maximum duration limit (in seconds) for this call */
640         void SetDurationLimit(
641                 long seconds /// duration limit to be set
642                 );
643
644         /** @return
645                 Duration limit (in seconds) set for this call.
646                 0 if call duration is not limited.
647         */
648         long GetDurationLimit() const;
649
650         /** This function can be used to determine, if the call has been
651                 disconnected due to call duration limit excess.
652
653                 @return
654                 true if the call duration limit has been exceeded, false otherwise.
655         */
656         bool IsDurationLimitExceeded() const;
657
658         /** @return
659                 Timestamp (number of seconds since 1st January 1970) for the call creation
660                 (when this CallRec object has been instantiated).
661         */
662         time_t GetCreationTime() const;
663
664         /** @return
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.
669         */
670         time_t GetSetupTime() const;
671
672         /** Set timestamp for a Setup message associated with this call. */
673         void SetSetupTime(
674                 time_t tm /// timestamp (seconds since 1st January 1970)
675                 );
676
677         /** @return
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.
682         */
683         time_t GetAlertingTime() const;
684
685         /** Set timestamp for a Alerting message associated with this call. */
686         void SetAlertingTime( 
687                 time_t tm /// timestamp (seconds since 1st January 1970)
688                 );
689
690         /** @return
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.
695         */
696         time_t GetConnectTime() const;
697
698         /** Set timestamp for a Connect (or ACF) message associated with this call. */
699         void SetConnectTime(
700                 time_t tm /// timestamp (seconds since 1st January 1970)
701                 );
702
703         /** @return
704                 Timestamp (number of seconds since 1st January 1970)
705                 for the call disconnect event. 0 if call has not been yet disconnected
706                 or connected.
707         */
708         time_t GetDisconnectTime() const;
709
710         /** Set timestamp for a disconnect event for this call. */
711         void SetDisconnectTime(
712                 time_t tm /// timestamp (seconds since 1st January 1970)
713                 );
714
715         /** @return
716                 Timestamp for the most recent accounting update event logged for this call.
717         */
718         time_t GetLastAcctUpdateTime() const { return m_acctUpdateTime; }
719
720         /** Set timestamp for the most recent accounting update event logged
721                 for this call.
722         */
723         void SetLastAcctUpdateTime(
724                 const time_t tm /// timestamp of the recent accounting update operation
725                 )
726         {
727                 m_acctUpdateTime = tm;
728         }
729
730         /** Check if:
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
735
736                 @return
737                 true if call is timed out and should be disconnected, false otherwise.
738         */
739         bool IsTimeout(
740                 /// point in time for timeouts to be measured relatively to
741                 /// (made as a parameter for performance reasons)
742                 const time_t now
743                 ) const;
744
745         /** @return
746                 Call duration in seconds. 0 for unconnected calls. Actual
747                 duration for calls in progress.
748         */
749         long GetDuration() const;
750
751         /** @return
752                 Call total time in seconds. 0 for calls without disconnect.
753         */
754         long GetTotalCallDuration() const;
755
756         /** @return
757                 Call Post Dial Delay in seconds.
758         */
759         long GetPostDialDelay() const;
760
761         /** @return
762                 Call ring time in seconds. 0 for calls without Alerting.
763         */
764         long GetRingTime() const;
765
766         /** @return
767                 A string that identifies uniquelly this call for accounting
768                 purposes. This string should be unique across subsequent GK
769                 start/stop events.
770         */
771         PString GetAcctSessionId() const { return m_acctSessionId; }
772
773         /** @return
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').
779         */
780         PString GetSrcInfo() const { return m_srcInfo; }
781
782         /** Set a new address for the calling party signalling channel.
783         */
784         void SetSrcSignalAddr(
785                 const H225_TransportAddress & addr /// new signalling transport address
786                 );
787
788         /** Set the unregistered calling party signalling channel as NATed.
789         */
790         void SetSrcNATed(PIPSocket::Address & natip);
791
792         /** Set a new address for the called party signalling channel.
793         */
794         void SetDestSignalAddr(
795                 const H225_TransportAddress & addr /// new signalling transport address
796                 );
797
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.
801
802                 @return
803                 true if the address has been retrieved successfully, false otherwise.
804         */
805         bool GetSrcSignalAddr(
806                 PIPSocket::Address& addr, /// will receive the IP address
807                 WORD& port /// will receive the port number
808                 ) const;
809
810         H225_TransportAddress GetDestSignalAddr() const;
811
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.
815
816                 @return
817                 true if the address has been retrieved successfully, false otherwise.
818         */
819         bool GetDestSignalAddr(
820                 PIPSocket::Address& addr, /// will receive the IP address
821                 WORD& port /// will receive the port number
822                 ) const;
823
824         /** @return
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').
832         */
833         PString GetDestInfo() const { return m_destInfo; }
834
835         /** @return
836             Calling party's aliases, as presented in ARQ or Setup messages.
837             This does not change during the call.
838         */
839         const H225_ArrayOf_AliasAddress& GetSourceAddress() const 
840                 { return m_sourceAddress; }
841                 
842         /** @return
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.
846         */
847         const H225_ArrayOf_AliasAddress& GetDestinationAddress() const
848                 { return m_destinationAddress; }
849
850         /** @return
851             Calling party's number or an empty string, if the number has not been
852             yet determined.
853         */
854         PString GetCallingStationId();
855         
856         /// Set calling party's number
857         void SetCallingStationId(
858                 const PString& id /// Calling-Station-Id
859                 );
860                 
861         /** @return
862             Called party's number or an empty string, if the number has not been
863             yet determined.
864         */
865         PString GetCalledStationId();
866
867         /// Set call linkage This the party to be charged for the call. 
868         void SetCallLinkage(
869                 const PString& id /// Calling-Station-Id (to be charged)
870                 );
871
872         /** @return
873         Call party to be charged for the call.
874         */
875         PString GetCallLinkage()const { return m_callLinkage; };
876
877
878         /// Set calling party's number
879         void SetCalledStationId(
880                 const PString& id /// Called-Station-Id
881                 );
882
883         /** @return
884             Called party's number before rewrite or an empty string, 
885             if the number has not been yet determined.
886         */
887         PString GetDialedNumber();
888
889         /// Set dialed number
890         void SetDialedNumber(
891                 const PString& number /// Dialed-Number
892                 );
893
894         /** @return
895             Fixed destination address for the call (NULL if not set).
896         */
897         H225_AliasAddress* GetRouteToAlias() const;
898         
899         /// Set fixed destination address for the call
900         void SetRouteToAlias(
901                 const H225_AliasAddress& alias /// alias to set
902                 );
903
904         // smart pointer for CallRec
905         typedef SmartPtr<CallRec> Ptr;
906
907         /// update IRR timers
908         void Update(const H225_InfoRequestResponse & irr);
909
910         void SetNewRoutes(
911                 const std::list<Routing::Route> &routes
912                 );
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();
916
917         bool IsCallInProgress() const;
918         void SetCallInProgress();
919
920         bool IsH245ResponseReceived() const;
921         void SetH245ResponseReceived();
922         
923         bool IsFastStartResponseReceived() const;
924         void SetFastStartResponseReceived();
925
926         bool SingleFailoverCDR() const;
927         int GetNoCallAttempts() const;
928         int GetNoRemainingRoutes() const;
929         bool DisableRetryChecks() const;
930
931         void SetCodec(const PString &codec);
932         PString GetCodec() const;
933
934         void SetMediaOriginatingIp(const PIPSocket::Address &addr);
935         bool GetMediaOriginatingIp(PIPSocket::Address &addr) const;
936
937         void SetRADIUSClass(const PBYTEArray &bytes);
938         void SetRADIUSClass(void * bytes, PINDEX len);
939         PBYTEArray GetRADIUSClass() const;
940
941 private:
942         void SendDRQ();
943         void InternalSetEP(endptr &, const endptr &);
944
945         CallRec(const CallRec & Other);
946         CallRec & operator= (const CallRec & other);
947
948 private:
949         /// internal call number generated by the gatekeeper
950         PINDEX m_CallNumber;
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
956         WORD m_crv;
957         /// EndpointRec for the calling party (if it is a registered endpoint)
958         /// NOTE: it does not change during CallRec lifetime
959         endptr m_Calling;
960         /// EndpointRec for the called party (if it is a registered endpoint)
961         /// NOTE: it can change during CallRec lifetime
962         endptr m_Called;
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
968         PString m_srcInfo;
969         /// called party aliases in a string form
970         PString m_destInfo;
971         /// bandwidth occupied by this call (as declared in ARQ)
972         int m_bandwidth;
973
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;
980
981         /// current timeout (or duration limit) for the call
982         long m_timeout;
983         /// timestamp for call timeout measuring
984         time_t m_timer;
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
989         time_t m_setupTime;
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;
1021
1022         CallSignalSocket *m_callingSocket, *m_calledSocket;
1023
1024         int m_usedCount;
1025         mutable PTimedMutex m_usedLock, m_sockLock;
1026         int m_nattype;
1027
1028         /// unregistered caller NAT'd
1029         bool m_unregNAT;
1030         PIPSocket::Address m_srcunregNATAddress;
1031
1032         bool m_h245Routed;
1033         /// the call is routed to this gatekeeper's parent gatekeeper
1034         bool m_toParent;
1035         bool m_forwarded;
1036         endptr m_Forwarder;
1037
1038         /// enable/disable proxy mode (override global settings from the config)
1039         int m_proxyMode;
1040         
1041         H225_ArrayOf_CryptoH323Token m_accessTokens;
1042
1043         /// IRR checking
1044         long m_irrFrequency;
1045         bool m_irrCheck;
1046         time_t m_irrCallerTimer;
1047         time_t m_irrCalleeTimer;
1048         
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;
1055         
1056         PString m_codec;
1057         PIPSocket::Address m_mediaOriginatingIp;
1058         PBYTEArray m_radiusClass;
1059 };
1060
1061 typedef CallRec::Ptr callptr;
1062
1063 // all active calls
1064 class CallTable : public Singleton<CallTable>
1065 {
1066 public:
1067         typedef std::list<CallRec *>::iterator iterator;
1068         typedef std::list<CallRec *>::const_iterator const_iterator;
1069
1070         CallTable();
1071         ~CallTable();
1072
1073         void Insert(CallRec * NewRec);
1074
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; }
1080
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;
1086
1087         void ClearTable();
1088         void CheckCalls(
1089                 RasServer* rassrv // to avoid call RasServer::Instance every second
1090                 );
1091
1092         void RemoveCall(const H225_DisengageRequest & obj_drq, const endptr &);
1093         void RemoveCall(const callptr &);
1094         void RemoveFailedLeg(const callptr &);
1095
1096         void PrintCurrentCalls(USocket *client, BOOL verbose=FALSE) const;
1097         PString PrintStatistics() const;
1098
1099         void AddForwardedCall(const callptr &);
1100         endptr IsForwardedCall(const callptr &);
1101
1102         void LoadConfig();
1103
1104         PINDEX Size() const { return m_activeCall; }
1105
1106         /** @return
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.
1110         */
1111         long GetSignalTimeout() const { return m_signalTimeout; }
1112
1113         /** @return
1114             Timeout value for Connect message to be received after a call entered
1115             the Alerting state. The value is expressed in milliseconds.
1116         */
1117         long GetAlertingTimeout() const { return m_alertingTimeout; }
1118
1119         /** @return
1120                 Default call duration limit value (seconds).
1121         */
1122         long GetDefaultDurationLimit() const { return m_defaultDurationLimit; }
1123
1124         /// @return     True to log accounting for each call leg
1125         bool SingleFailoverCDR() const { return m_singleFailoverCDR; }
1126
1127 private:
1128         template<class F> callptr InternalFind(const F & FindObject) const
1129         {
1130                 ReadLock lock(listLock);
1131                 const_iterator Iter(find_if(CallList.begin(), CallList.end(), FindObject));
1132                 return callptr((Iter != CallList.end()) ? *Iter : 0);
1133         }
1134
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);
1140
1141         void InternalStatistics(unsigned & n, unsigned & act, unsigned & nb, unsigned & np, PString & msg, BOOL verbose) const;
1142
1143         std::list<CallRec *> CallList;
1144         std::list<CallRec *> RemovedList;
1145
1146         bool m_genNBCDR;
1147         bool m_genUCCDR;
1148
1149         PINDEX m_CallNumber;
1150         mutable PReadWriteMutex listLock;
1151
1152         int m_capacity;
1153
1154         // statistics
1155         unsigned m_CallCount, m_successCall, m_neighborCall, m_parentCall, m_activeCall;
1156
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;
1171
1172         CallTable(const CallTable &);
1173         CallTable& operator==(const CallTable &);
1174 };
1175
1176 // inline functions of EndpointRec
1177 inline H225_TransportAddress EndpointRec::GetRasAddress() const
1178
1179         PWaitAndSignal lock(m_usedLock);
1180         return m_rasAddress;
1181 }
1182
1183 inline void EndpointRec::SetRasAddress(const H225_TransportAddress & addr)
1184
1185         PWaitAndSignal lock(m_usedLock);
1186         m_rasAddress = addr;
1187 }
1188
1189 inline void EndpointRec::SetCallSignalAddress(const H225_TransportAddress & addr) 
1190 {
1191         PWaitAndSignal lock(m_usedLock);
1192     m_callSignalAddress = addr;
1193 }
1194
1195 inline H225_TransportAddress EndpointRec::GetCallSignalAddress() const
1196
1197         PWaitAndSignal lock(m_usedLock);
1198         return m_callSignalAddress;
1199 }
1200
1201 inline H225_EndpointIdentifier EndpointRec::GetEndpointIdentifier() const
1202 {
1203         PWaitAndSignal lock(m_usedLock);
1204         return m_endpointIdentifier;
1205 }
1206   
1207 inline int EndpointRec::GetTimeToLive() const
1208 {
1209         return m_timeToLive;
1210 }
1211
1212 inline H225_ArrayOf_AliasAddress EndpointRec::GetAliases() const
1213 {
1214         PWaitAndSignal lock(m_usedLock);
1215         return m_terminalAliases;
1216 }
1217
1218 inline H225_EndpointType EndpointRec::GetEndpointType() const
1219 {
1220         PWaitAndSignal lock(m_usedLock);
1221         return *m_terminalType;
1222 }
1223
1224 inline void EndpointRec::SetNAT(bool nat)
1225
1226         m_nat = nat;
1227 }
1228
1229 inline void EndpointRec::SetSupportNAT(bool support)
1230 {
1231         m_natsupport = support;
1232 }
1233
1234 inline bool EndpointRec::IsNATed() const
1235
1236         return m_nat;
1237 }
1238
1239 inline bool EndpointRec::SupportNAT() const
1240 {
1241         return m_natsupport;
1242 }
1243
1244 inline PIPSocket::Address EndpointRec::GetNATIP() const
1245 {
1246         PWaitAndSignal lock(m_usedLock);
1247         return m_natip;
1248 }
1249
1250 inline CallSignalSocket *EndpointRec::GetSocket() 
1251 {
1252         PWaitAndSignal lock(m_usedLock);
1253         CallSignalSocket *socket = m_natsocket;
1254         m_natsocket = 0;
1255         return socket;
1256 }
1257
1258 inline bool EndpointRec::IsPermanent() const
1259 {
1260         return m_permanent;
1261 }
1262
1263 inline bool EndpointRec::IsUsed() const
1264 {
1265         PWaitAndSignal lock(m_usedLock);
1266         return (m_activeCall > 0 || m_usedCount > 0);
1267 }
1268
1269 inline bool EndpointRec::IsUpdated(const PTime *now) const
1270 {
1271         PWaitAndSignal lock(m_usedLock);
1272         return (!m_timeToLive || (*now - m_updatedTime).GetSeconds() < m_timeToLive);
1273 }
1274
1275 inline bool EndpointRec::IsFromParent() const
1276 {
1277         return m_fromParent;
1278 }
1279
1280 inline bool EndpointRec::HasNATSocket() const
1281 {
1282         return m_natsocket;
1283 }
1284
1285 inline PTime EndpointRec::GetUpdatedTime() const
1286
1287         PWaitAndSignal lock(m_usedLock);
1288         return m_updatedTime;
1289 }
1290
1291 inline H225_RasMessage EndpointRec::GetCompleteRegistrationRequest() const
1292
1293         PWaitAndSignal lock(m_usedLock);
1294         return m_RasMsg;
1295 }
1296
1297 inline bool EndpointRec::HasCallCreditCapabilities() const
1298
1299         return m_hasCallCreditCapabilities;
1300 }
1301
1302 inline void EndpointRec::AddCall()
1303 {
1304         PWaitAndSignal lock(m_usedLock);
1305         ++m_activeCall, ++m_totalCall;
1306 }
1307
1308 inline void EndpointRec::AddConnectedCall()
1309 {
1310         PWaitAndSignal lock(m_usedLock);
1311         ++m_connectedCall;
1312 }
1313
1314 inline void EndpointRec::RemoveCall()
1315 {
1316         PWaitAndSignal lock(m_usedLock);
1317         --m_activeCall;
1318 }
1319
1320 inline void EndpointRec::Lock()
1321 {
1322         PWaitAndSignal lock(m_usedLock);
1323         ++m_usedCount;
1324 }
1325
1326 inline void EndpointRec::Unlock()
1327 {
1328         PWaitAndSignal lock(m_usedLock);
1329         --m_usedCount;
1330 }
1331
1332 // inline functions of CallRec
1333 inline void CallRec::Lock()
1334 {
1335         PWaitAndSignal lock(m_usedLock);
1336         ++m_usedCount;
1337 }
1338
1339 inline void CallRec::Unlock()
1340 {
1341         PWaitAndSignal lock(m_usedLock);
1342         --m_usedCount;
1343 }
1344
1345 inline bool CallRec::CompareCallId(const H225_CallIdentifier *CallId) const
1346 {
1347         return (m_callIdentifier == *CallId);
1348 }
1349
1350 inline bool CallRec::CompareCRV(WORD crv) const
1351 {
1352         return m_crv == (crv & 0x7fffu);
1353 }
1354
1355 inline bool CallRec::CompareCallNumber(PINDEX CallNumber) const
1356 {
1357         return (m_CallNumber == CallNumber);
1358 }
1359
1360 inline bool CallRec::CompareEndpoint(const endptr *ep) const
1361 {
1362         return (m_Calling && m_Calling == *ep) || (m_Called && m_Called == *ep);
1363 }
1364
1365 inline bool CallRec::CompareSigAdr(const H225_TransportAddress *adr) const
1366 {
1367         return (m_Calling && m_Calling->GetCallSignalAddress() == *adr) ||
1368                 (m_Called && m_Called->GetCallSignalAddress() == *adr);
1369 }
1370
1371 inline long CallRec::GetDurationLimit() const
1372 {
1373         return m_durationLimit;
1374 }
1375
1376 inline time_t CallRec::GetCreationTime() const
1377 {
1378         return m_creationTime;
1379 }
1380
1381 inline time_t CallRec::GetSetupTime() const
1382 {
1383         return m_setupTime;
1384 }
1385
1386 inline time_t CallRec::GetAlertingTime() const
1387 {
1388         return m_alertingTime;
1389 }
1390
1391 inline time_t CallRec::GetConnectTime() const
1392 {
1393         return m_connectTime;
1394 }
1395
1396 inline time_t CallRec::GetDisconnectTime() const
1397 {
1398         return m_disconnectTime;
1399 }
1400
1401 inline unsigned CallRec::GetDisconnectCause() const
1402 {
1403         return m_disconnectCause;
1404 }
1405
1406 inline void CallRec::SetDisconnectCause( unsigned causeCode )
1407 {
1408         // set the cause only if it has not been already set
1409         if( m_disconnectCause == 0 )
1410                 m_disconnectCause = causeCode;
1411 }
1412
1413 inline bool CallRec::IsTimeout(const time_t now) const
1414 {
1415         bool result = (m_timeout > 0) && (now >= m_timer) && ((now - m_timer) >= m_timeout);
1416         if (m_irrCheck && (m_irrFrequency > 0)) {
1417                 if (m_Calling)
1418                         result |= (now >= m_irrCallerTimer) && ((now - m_irrCallerTimer) >= 2 * m_irrFrequency);
1419                 if (m_Called)
1420                         result |= (now >= m_irrCalleeTimer) && ((now - m_irrCalleeTimer) >= 2 * m_irrFrequency);
1421         }
1422         return result;
1423 }
1424
1425 #endif // RASTBL_H