gkserver.h

Go to the documentation of this file.
00001 /*
00002  * gkserver.h
00003  *
00004  * H225 Registration Admission and Security protocol handler
00005  *
00006  * Open H323 Library
00007  *
00008  * Copyright (c) 1998-2001 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open H323 Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * This code was based on original code from OpenGate of Egoboo Ltd. thanks
00025  * to Ashley Unitt for his efforts.
00026  *
00027  * Contributor(s): ______________________________________.
00028  *
00029  * $Revision: 19279 $
00030  * $Author: rjongbloed $
00031  * $Date: 2008-01-17 04:08:34 +0000 (Thu, 17 Jan 2008) $
00032  */
00033 
00034 #ifndef __OPAL_GKSERVER_H
00035 #define __OPAL_GKSERVER_H
00036 
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040 
00041 
00042 #include <ptlib/safecoll.h>
00043 #include <opal/guid.h>
00044 #include <h323/h225ras.h>
00045 #include <h323/transaddr.h>
00046 #include <h323/h235auth.h>
00047 #include <h323/h323pdu.h>
00048 #include <h323/h323trans.h>
00049 
00050 
00051 class PASN_Sequence;
00052 class PASN_Choice;
00053 
00054 class H225_AliasAddress;
00055 class H225_EndpointIdentifier;
00056 class H225_GatekeeperIdentifier;
00057 class H225_ArrayOf_TransportAddress;
00058 class H225_GatekeeperIdentifier;
00059 class H225_EndpointIdentifier;
00060 class H225_InfoRequestResponse_perCallInfo_subtype;
00061 class H225_RasUsageInformation;
00062 
00063 class H323RegisteredEndPoint;
00064 class H323GatekeeperListener;
00065 class H323GatekeeperServer;
00066 class H323RasPDU;
00067 class H323PeerElement;
00068 
00069 
00070 class H323GatekeeperRequest : public H323Transaction
00071 {
00072     PCLASSINFO(H323GatekeeperRequest, H323Transaction);
00073   public:
00078     H323GatekeeperRequest(
00079       H323GatekeeperListener & rasChannel,
00080       const H323RasPDU & pdu
00081     );
00083 
00084     virtual H323TransactionPDU * CreateRIP(
00085       unsigned sequenceNumber,
00086       unsigned delay
00087     ) const;
00088 
00089     virtual PBoolean WritePDU(
00090       H323TransactionPDU & pdu
00091     );
00092     PBoolean CheckCryptoTokens();
00093     PBoolean CheckGatekeeperIdentifier();
00094     PBoolean GetRegisteredEndPoint();
00095 
00096     virtual PString GetGatekeeperIdentifier() const = 0;
00097     virtual unsigned GetGatekeeperRejectTag() const = 0;
00098     virtual PString GetEndpointIdentifier() const = 0;
00099     virtual unsigned GetRegisteredEndPointRejectTag() const = 0;
00100     virtual unsigned GetSecurityRejectTag() const = 0;
00101 
00102     H323GatekeeperListener & GetRasChannel() const { return rasChannel; }
00103 
00104     PSafePtr<H323RegisteredEndPoint> endpoint;
00105 
00106   protected:
00107     H323GatekeeperListener & rasChannel;
00108 };
00109 
00110 
00111 class H323GatekeeperGRQ : public H323GatekeeperRequest
00112 {
00113     PCLASSINFO(H323GatekeeperGRQ, H323GatekeeperRequest);
00114   public:
00115     H323GatekeeperGRQ(
00116       H323GatekeeperListener & listener,
00117       const H323RasPDU & pdu
00118     );
00119 
00120 #if PTRACING
00121     virtual const char * GetName() const;
00122 #endif
00123     virtual PString GetGatekeeperIdentifier() const;
00124     virtual unsigned GetGatekeeperRejectTag() const;
00125     virtual PString GetEndpointIdentifier() const;
00126     virtual unsigned GetRegisteredEndPointRejectTag() const;
00127     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00128     virtual unsigned GetSecurityRejectTag() const;
00129     virtual void SetRejectReason(
00130       unsigned reasonCode
00131     );
00132 
00133     H225_GatekeeperRequest & grq;
00134     H225_GatekeeperConfirm & gcf;
00135     H225_GatekeeperReject  & grj;
00136 
00137   protected:
00138     virtual Response OnHandlePDU();
00139 };
00140 
00141 
00142 class H323GatekeeperRRQ : public H323GatekeeperRequest
00143 {
00144     PCLASSINFO(H323GatekeeperRRQ, H323GatekeeperRequest);
00145   public:
00146     H323GatekeeperRRQ(
00147       H323GatekeeperListener & listener,
00148       const H323RasPDU & pdu
00149     );
00150 
00151 #if PTRACING
00152     virtual const char * GetName() const;
00153 #endif
00154     virtual PString GetGatekeeperIdentifier() const;
00155     virtual unsigned GetGatekeeperRejectTag() const;
00156     virtual PString GetEndpointIdentifier() const;
00157     virtual unsigned GetRegisteredEndPointRejectTag() const;
00158     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00159     virtual unsigned GetSecurityRejectTag() const;
00160     virtual void SetRejectReason(
00161       unsigned reasonCode
00162     );
00163 
00164     H225_RegistrationRequest & rrq;
00165     H225_RegistrationConfirm & rcf;
00166     H225_RegistrationReject  & rrj;
00167 
00168   protected:
00169     virtual Response OnHandlePDU();
00170 };
00171 
00172 
00173 class H323GatekeeperURQ : public H323GatekeeperRequest
00174 {
00175     PCLASSINFO(H323GatekeeperURQ, H323GatekeeperRequest);
00176   public:
00177     H323GatekeeperURQ(
00178       H323GatekeeperListener & listener,
00179       const H323RasPDU & pdu
00180     );
00181 
00182 #if PTRACING
00183     virtual const char * GetName() const;
00184 #endif
00185     virtual PString GetGatekeeperIdentifier() const;
00186     virtual unsigned GetGatekeeperRejectTag() const;
00187     virtual PString GetEndpointIdentifier() const;
00188     virtual unsigned GetRegisteredEndPointRejectTag() const;
00189     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00190     virtual unsigned GetSecurityRejectTag() const;
00191     virtual void SetRejectReason(
00192       unsigned reasonCode
00193     );
00194 
00195     H225_UnregistrationRequest & urq;
00196     H225_UnregistrationConfirm & ucf;
00197     H225_UnregistrationReject  & urj;
00198 
00199   protected:
00200     virtual Response OnHandlePDU();
00201 };
00202 
00203 
00204 class H323GatekeeperARQ : public H323GatekeeperRequest
00205 {
00206     PCLASSINFO(H323GatekeeperARQ, H323GatekeeperRequest);
00207   public:
00208     H323GatekeeperARQ(
00209       H323GatekeeperListener & listener,
00210       const H323RasPDU & pdu
00211     );
00212 
00213 #if PTRACING
00214     virtual const char * GetName() const;
00215 #endif
00216     virtual PString GetGatekeeperIdentifier() const;
00217     virtual unsigned GetGatekeeperRejectTag() const;
00218     virtual PString GetEndpointIdentifier() const;
00219     virtual unsigned GetRegisteredEndPointRejectTag() const;
00220     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00221     virtual unsigned GetSecurityRejectTag() const;
00222     virtual void SetRejectReason(
00223       unsigned reasonCode
00224     );
00225 
00226     H225_AdmissionRequest & arq;
00227     H225_AdmissionConfirm & acf;
00228     H225_AdmissionReject  & arj;
00229 
00230     PString alternateSecurityID;
00231 
00232   protected:
00233     virtual Response OnHandlePDU();
00234 };
00235 
00236 
00237 class H323GatekeeperDRQ : public H323GatekeeperRequest
00238 {
00239     PCLASSINFO(H323GatekeeperDRQ, H323GatekeeperRequest);
00240   public:
00241     H323GatekeeperDRQ(
00242       H323GatekeeperListener & listener,
00243       const H323RasPDU & pdu
00244     );
00245 
00246 #if PTRACING
00247     virtual const char * GetName() const;
00248 #endif
00249     virtual PString GetGatekeeperIdentifier() const;
00250     virtual unsigned GetGatekeeperRejectTag() const;
00251     virtual PString GetEndpointIdentifier() const;
00252     virtual unsigned GetRegisteredEndPointRejectTag() const;
00253     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00254     virtual unsigned GetSecurityRejectTag() const;
00255     virtual void SetRejectReason(
00256       unsigned reasonCode
00257     );
00258 
00259     H225_DisengageRequest & drq;
00260     H225_DisengageConfirm & dcf;
00261     H225_DisengageReject  & drj;
00262 
00263   protected:
00264     virtual Response OnHandlePDU();
00265 };
00266 
00267 
00268 class H323GatekeeperBRQ : public H323GatekeeperRequest
00269 {
00270     PCLASSINFO(H323GatekeeperBRQ, H323GatekeeperRequest);
00271   public:
00272     H323GatekeeperBRQ(
00273       H323GatekeeperListener & listener,
00274       const H323RasPDU & pdu
00275     );
00276 
00277 #if PTRACING
00278     virtual const char * GetName() const;
00279 #endif
00280     virtual PString GetGatekeeperIdentifier() const;
00281     virtual unsigned GetGatekeeperRejectTag() const;
00282     virtual PString GetEndpointIdentifier() const;
00283     virtual unsigned GetRegisteredEndPointRejectTag() const;
00284     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00285     virtual unsigned GetSecurityRejectTag() const;
00286     virtual void SetRejectReason(
00287       unsigned reasonCode
00288     );
00289 
00290     H225_BandwidthRequest & brq;
00291     H225_BandwidthConfirm & bcf;
00292     H225_BandwidthReject  & brj;
00293 
00294   protected:
00295     virtual Response OnHandlePDU();
00296 };
00297 
00298 
00299 class H323GatekeeperLRQ : public H323GatekeeperRequest
00300 {
00301     PCLASSINFO(H323GatekeeperLRQ, H323GatekeeperRequest);
00302   public:
00303     H323GatekeeperLRQ(
00304       H323GatekeeperListener & listener,
00305       const H323RasPDU & pdu
00306     );
00307 
00308 #if PTRACING
00309     virtual const char * GetName() const;
00310 #endif
00311     virtual PString GetGatekeeperIdentifier() const;
00312     virtual unsigned GetGatekeeperRejectTag() const;
00313     virtual PString GetEndpointIdentifier() const;
00314     virtual unsigned GetRegisteredEndPointRejectTag() const;
00315     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00316     virtual unsigned GetSecurityRejectTag() const;
00317     virtual void SetRejectReason(
00318       unsigned reasonCode
00319     );
00320 
00321     H225_LocationRequest & lrq;
00322     H225_LocationConfirm & lcf;
00323     H225_LocationReject  & lrj;
00324 
00325   protected:
00326     virtual Response OnHandlePDU();
00327 };
00328 
00329 
00330 class H323GatekeeperIRR : public H323GatekeeperRequest
00331 {
00332     PCLASSINFO(H323GatekeeperIRR, H323GatekeeperRequest);
00333   public:
00334     H323GatekeeperIRR(
00335       H323GatekeeperListener & listener,
00336       const H323RasPDU & pdu
00337     );
00338 
00339 #if PTRACING
00340     virtual const char * GetName() const;
00341 #endif
00342     virtual PString GetGatekeeperIdentifier() const;
00343     virtual unsigned GetGatekeeperRejectTag() const;
00344     virtual PString GetEndpointIdentifier() const;
00345     virtual unsigned GetRegisteredEndPointRejectTag() const;
00346     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00347     virtual unsigned GetSecurityRejectTag() const;
00348     virtual void SetRejectReason(
00349       unsigned reasonCode
00350     );
00351 
00352     H225_InfoRequestResponse & irr;
00353     H225_InfoRequestAck      & iack;
00354     H225_InfoRequestNak      & inak;
00355 
00356   protected:
00357     virtual Response OnHandlePDU();
00358 };
00359 
00360 
00363 class H323GatekeeperCall : public PSafeObject
00364 {
00365     PCLASSINFO(H323GatekeeperCall, PSafeObject);
00366   public:
00369     enum Direction {
00370       AnsweringCall,
00371       OriginatingCall,
00372       UnknownDirection
00373     };
00374 
00377     H323GatekeeperCall(
00378       H323GatekeeperServer & server,               
00379       const OpalGloballyUniqueID & callIdentifier, 
00380       Direction direction                          
00381     );
00382 
00385     ~H323GatekeeperCall();
00387 
00392     Comparison Compare(
00393       const PObject & obj  
00394     ) const;
00395 
00398     void PrintOn(
00399       ostream & strm    
00400     ) const;
00402 
00410     virtual H323GatekeeperRequest::Response OnAdmission(
00411       H323GatekeeperARQ & request
00412     );
00413 
00417     virtual PBoolean Disengage(
00418       int reason = -1   
00419     );
00420 
00424     virtual H323GatekeeperRequest::Response OnDisengage(
00425       H323GatekeeperDRQ & request
00426     );
00427 
00432     virtual H323GatekeeperRequest::Response OnBandwidth(
00433       H323GatekeeperBRQ & request
00434     );
00435 
00439     virtual H323GatekeeperRequest::Response OnInfoResponse(
00440       H323GatekeeperIRR & request,
00441       H225_InfoRequestResponse_perCallInfo_subtype & call
00442     );
00443 
00446     virtual void OnAlerting();
00447 
00450     virtual void OnConnected();
00451 
00462     virtual PBoolean OnHeartbeat();
00463 
00470     virtual PString GetCallCreditAmount() const;
00471 
00478     virtual PBoolean GetCallCreditMode() const;
00479 
00487     virtual unsigned GetDurationLimit() const;
00488 
00493     virtual PBoolean SendCallCreditServiceControl();
00494 
00497     PBoolean AddCallCreditServiceControl(
00498       H225_ArrayOf_ServiceControlSession & serviceControl
00499     ) const;
00500 
00505     virtual PBoolean SendServiceControlSession(
00506       const H323ServiceControlSession & session
00507     );
00508 
00514     virtual PBoolean TranslateAliasAddress(
00515       const H225_AliasAddress & alias,
00516       H225_ArrayOf_AliasAddress & aliases,
00517       H323TransportAddress & address,
00518       PBoolean & isGkRouted
00519     );
00520 
00522 
00525     H323GatekeeperServer & GetGatekeeper() const { return gatekeeper; }
00526     H323RegisteredEndPoint & GetEndPoint() const { return *PAssertNULL(endpoint); }
00527     PBoolean IsAnsweringCall() const { return direction == AnsweringCall; }
00528     unsigned GetCallReference() const { return callReference; }
00529     const OpalGloballyUniqueID & GetCallIdentifier() const { return callIdentifier; }
00530     const OpalGloballyUniqueID & GetConferenceIdentifier() const { return conferenceIdentifier; }
00531     const PString & GetSourceNumber() const { return srcNumber; }
00532     const PStringArray & GetSourceAliases() const { return srcAliases; }
00533     const H323TransportAddress & GetSourceHost() const { return srcHost; }
00534     PString GetSourceAddress() const;
00535     const PString & GetDestinationNumber() const { return dstNumber; }
00536     const PStringArray & GetDestinationAliases() const { return dstAliases; }
00537     const H323TransportAddress & GetDestinationHost() const { return dstHost; }
00538     PString GetDestinationAddress() const;
00539     unsigned GetBandwidthUsed() const { return bandwidthUsed; }
00540     PBoolean SetBandwidthUsed(unsigned bandwidth);
00541     const PTime & GetLastInfoResponseTime() const { return lastInfoResponse; }
00542     const PTime & GetCallStartTime() const { return callStartTime; }
00543     const PTime & GetAlertingTime() const { return alertingTime; }
00544     const PTime & GetConnectedTime() const { return connectedTime; }
00545     const PTime & GetCallEndTime() const { return callEndTime; }
00546     H323Connection::CallEndReason GetCallEndReason() const { return callEndReason; }
00548 
00549   protected:
00550     void SetUsageInfo(const H225_RasUsageInformation & usage);
00551 
00552     H323GatekeeperServer   & gatekeeper;
00553     H323RegisteredEndPoint * endpoint;
00554     H323GatekeeperListener * rasChannel;
00555 
00556     Direction            direction;
00557     unsigned             callReference;
00558     OpalGloballyUniqueID callIdentifier;
00559     OpalGloballyUniqueID conferenceIdentifier;
00560     PString              srcNumber;
00561     PStringArray         srcAliases;
00562     H323TransportAddress srcHost;
00563     PString              dstNumber;
00564     PStringArray         dstAliases;
00565     H323TransportAddress dstHost;
00566     unsigned             bandwidthUsed;
00567     unsigned             infoResponseRate;
00568     PTime                lastInfoResponse;
00569 
00570     PBoolean                          drqReceived;
00571     PTime                         callStartTime;
00572     PTime                         alertingTime;
00573     PTime                         connectedTime;
00574     PTime                         callEndTime;
00575     H323Connection::CallEndReason callEndReason;
00576 };
00577 
00578 
00584 class H323RegisteredEndPoint : public PSafeObject
00585 {
00586     PCLASSINFO(H323RegisteredEndPoint, PSafeObject);
00587   public:
00592     H323RegisteredEndPoint(
00593       H323GatekeeperServer & server, 
00594       const PString & id             
00595     );
00597 
00602     Comparison Compare(
00603       const PObject & obj  
00604     ) const;
00605 
00608     void PrintOn(
00609       ostream & strm    
00610     ) const;
00612 
00619     virtual void AddCall(
00620       H323GatekeeperCall * call
00621     );
00622 
00627     virtual PBoolean RemoveCall(
00628       H323GatekeeperCall * call
00629     );
00630 
00633     PINDEX GetCallCount() const { return activeCalls.GetSize(); }
00634 
00637     H323GatekeeperCall & GetCall(
00638       PINDEX idx
00639     ) { return activeCalls[idx]; }
00641 
00650     virtual H323GatekeeperRequest::Response OnRegistration(
00651       H323GatekeeperRRQ & request
00652     );
00653 
00663     virtual H323GatekeeperRequest::Response OnFullRegistration(
00664       H323GatekeeperRRQ & request
00665     );
00666 
00675     virtual H323GatekeeperRequest::Response OnSecureRegistration(
00676       H323GatekeeperRRQ & request
00677     );
00678 
00682     virtual H323GatekeeperRequest::Response OnUnregistration(
00683       H323GatekeeperURQ & request
00684     );
00685 
00689     virtual PBoolean Unregister(
00690       int reason = -1   
00691     );
00692 
00697     virtual H323GatekeeperRequest::Response OnInfoResponse(
00698       H323GatekeeperIRR & request
00699     );
00700 
00711     virtual PBoolean OnTimeToLive();
00712 
00724     virtual PString GetCallCreditAmount() const;
00725 
00733     virtual PBoolean GetCallCreditMode() const;
00734 
00739     virtual PBoolean SendServiceControlSession(
00740       const H323ServiceControlSession & session
00741     );
00742 
00746     virtual PBoolean AddServiceControlSession(
00747       const H323ServiceControlSession & session,
00748       H225_ArrayOf_ServiceControlSession & serviceControl
00749     );
00751 
00756     virtual PBoolean SetPassword(
00757       const PString & password,
00758       const PString & username = PString::Empty()
00759     );
00760 
00763     const PString & GetIdentifier() const { return identifier; }
00764 
00767     const OpalGloballyUniqueID & GetDescriptorID() const { return descriptorID; }
00768 
00771     H323GatekeeperServer & GetGatekeeper() const { return gatekeeper; }
00772 
00776     const H323TransportAddressArray & GetRASAddresses() const { return rasAddresses; }
00777 
00781     PINDEX GetRASAddressCount() const { return rasAddresses.GetSize(); }
00782 
00786     H323TransportAddress GetRASAddress(
00787       PINDEX idx
00788     ) const { return rasAddresses[idx]; }
00789 
00793     const H323TransportAddressArray & GetSignalAddresses() const { return signalAddresses; }
00794 
00798     PINDEX GetSignalAddressCount() const { return signalAddresses.GetSize(); }
00799 
00803     H323TransportAddress GetSignalAddress(
00804       PINDEX idx
00805     ) const { return signalAddresses[idx]; }
00806 
00809     const PStringArray & GetAliases() const { return aliases; }
00810 
00813     PBoolean ContainsAlias(
00814       const PString & alias
00815       ) { return aliases.GetStringsIndex(alias) != P_MAX_INDEX; }
00816 
00819     PINDEX GetAliasCount() const { return aliases.GetSize(); }
00820 
00823     PString GetAlias(
00824       PINDEX idx
00825     ) const { if (idx < aliases.GetSize()) return aliases[idx]; return PString::Empty(); }
00826 
00832     void RemoveAlias(
00833       const PString & alias
00834     );
00835 
00838     virtual const H235Authenticators & GetAuthenticators() const { return authenticators; }
00839 
00842     PINDEX GetPrefixCount() const { return voicePrefixes.GetSize(); }
00843 
00846     PString GetPrefix(
00847       PINDEX idx
00848     ) const { return voicePrefixes[idx]; }
00849 
00852     PCaselessString GetApplicationInfo() const { return productInfo.AsString(); }
00853 
00856     const OpalProductInfo & GetProductInfo() const { return productInfo; }
00857 
00860     unsigned GetProtocolVersion() const { return protocolVersion; }
00861 
00864     PBoolean IsBehindNAT() const { return isBehindNAT; }
00865 
00868     PBoolean CanDisplayAmountString() const { return canDisplayAmountString; }
00869 
00872     PBoolean CanEnforceDurationLimit() const { return canEnforceDurationLimit; }
00873 
00876     PBoolean CanReceiveRIP() const;
00877 
00880     PBoolean GetH225Version() const { return h225Version; }
00882 
00892       virtual PBoolean OnSendDescriptorForEndpoint(
00893         H225_ArrayOf_AliasAddress & aliases,          
00894         H225_EndpointType & terminalType,             
00895         H225_ArrayOf_AliasAddress & transportAddresses  
00896       );
00898 
00899 
00900   protected:
00901     H323GatekeeperServer    & gatekeeper;
00902     H323GatekeeperListener  * rasChannel;
00903 
00904     PString                   identifier;
00905     OpalGloballyUniqueID      descriptorID;
00906     H323TransportAddressArray rasAddresses;
00907     H323TransportAddressArray signalAddresses;
00908     PStringArray              aliases;
00909     PStringArray              voicePrefixes;
00910     OpalProductInfo           productInfo;
00911     unsigned                  protocolVersion;
00912     PBoolean                      isBehindNAT;
00913     PBoolean                      canDisplayAmountString;
00914     PBoolean                      canEnforceDurationLimit;
00915     unsigned                  h225Version;
00916     unsigned                  timeToLive;
00917     H235Authenticators        authenticators;
00918 
00919     PTime lastRegistration;
00920     PTime lastInfoResponse;
00921 
00922     PSortedList<H323GatekeeperCall> activeCalls;
00923     POrdinalDictionary<PString>     serviceControlSessions;
00924 };
00925 
00926 
00932 class H323GatekeeperListener : public H225_RAS
00933 {
00934     PCLASSINFO(H323GatekeeperListener, H225_RAS);
00935   public:
00940     H323GatekeeperListener(
00941       H323EndPoint & endpoint,               
00942       H323GatekeeperServer & server,         
00943       const PString & gatekeeperIdentifier,  
00944       H323Transport * transport = NULL       
00945     );
00946 
00949     ~H323GatekeeperListener();
00951 
00956     PBoolean UnregistrationRequest(
00957       const H323RegisteredEndPoint & ep,
00958       unsigned reason
00959     );
00960 
00963     PBoolean DisengageRequest(
00964       const H323GatekeeperCall & call,
00965       unsigned reason
00966     );
00967 
00970     virtual PBoolean InfoRequest(
00971       H323RegisteredEndPoint & ep,
00972       H323GatekeeperCall * call = NULL
00973     );
00974 
00977     virtual PBoolean ServiceControlIndication(
00978       H323RegisteredEndPoint & ep,
00979       const H323ServiceControlSession & session,
00980       H323GatekeeperCall * call = NULL
00981     );
00983 
00990     virtual H323GatekeeperRequest::Response OnDiscovery(
00991       H323GatekeeperGRQ & request
00992     );
00993 
00998     virtual H323GatekeeperRequest::Response OnRegistration(
00999       H323GatekeeperRRQ & request
01000     );
01001 
01006     virtual H323GatekeeperRequest::Response OnUnregistration(
01007       H323GatekeeperURQ & request
01008     );
01009 
01014     virtual H323GatekeeperRequest::Response OnAdmission(
01015       H323GatekeeperARQ & request
01016     );
01017 
01022     virtual H323GatekeeperRequest::Response OnDisengage(
01023       H323GatekeeperDRQ & request
01024     );
01025 
01030     virtual H323GatekeeperRequest::Response OnBandwidth(
01031       H323GatekeeperBRQ & request
01032     );
01033 
01038     virtual H323GatekeeperRequest::Response OnLocation(
01039       H323GatekeeperLRQ & request
01040     );
01041 
01046     virtual H323GatekeeperRequest::Response OnInfoResponse(
01047       H323GatekeeperIRR & request
01048     );
01050 
01053     virtual PBoolean OnReceiveGatekeeperRequest(const H323RasPDU &, const H225_GatekeeperRequest &);
01054     virtual PBoolean OnReceiveRegistrationRequest(const H323RasPDU &, const H225_RegistrationRequest &);
01055     virtual PBoolean OnReceiveUnregistrationRequest(const H323RasPDU &, const H225_UnregistrationRequest &);
01056     virtual PBoolean OnReceiveUnregistrationConfirm(const H225_UnregistrationConfirm &);
01057     virtual PBoolean OnReceiveUnregistrationReject(const H225_UnregistrationReject &);
01058     virtual PBoolean OnReceiveAdmissionRequest(const H323RasPDU &, const H225_AdmissionRequest &);
01059     virtual PBoolean OnReceiveBandwidthRequest(const H323RasPDU &, const H225_BandwidthRequest &);
01060     virtual PBoolean OnReceiveBandwidthConfirm(const H225_BandwidthConfirm &);
01061     virtual PBoolean OnReceiveBandwidthReject(const H225_BandwidthReject &);
01062     virtual PBoolean OnReceiveDisengageRequest(const H323RasPDU &, const H225_DisengageRequest &);
01063     virtual PBoolean OnReceiveDisengageConfirm(const H225_DisengageConfirm &);
01064     virtual PBoolean OnReceiveDisengageReject(const H225_DisengageReject &);
01065     virtual PBoolean OnReceiveLocationRequest(const H323RasPDU &, const H225_LocationRequest &);
01066     virtual PBoolean OnReceiveInfoRequestResponse(const H323RasPDU &, const H225_InfoRequestResponse &);
01067     virtual PBoolean OnReceiveResourcesAvailableConfirm(const H225_ResourcesAvailableConfirm &);
01068     virtual PBoolean OnSendFeatureSet(unsigned, H225_FeatureSet & features) const;
01069     virtual void OnReceiveFeatureSet(unsigned, const H225_FeatureSet & features) const;
01071 
01074     H323GatekeeperServer & GetGatekeeper() const { return gatekeeper; }
01076 
01077 
01078   protected:
01079     H323GatekeeperServer & gatekeeper;
01080 };
01081 
01082 
01093 class H323GatekeeperServer : public H323TransactionServer
01094 {
01095     PCLASSINFO(H323GatekeeperServer, H323TransactionServer);
01096   public:
01101     H323GatekeeperServer(
01102       H323EndPoint & endpoint
01103     );
01104 
01107     ~H323GatekeeperServer();
01109 
01110     WORD GetDefaultUdpPort() { return H225_RAS::DefaultRasUdpPort; }
01111 
01122     virtual H323Transactor * CreateListener(
01123       H323Transport * transport  
01124     );
01125 
01127 
01133     virtual H323GatekeeperRequest::Response OnDiscovery(
01134       H323GatekeeperGRQ & request
01135     );
01136 
01144     virtual H323GatekeeperRequest::Response OnRegistration(
01145       H323GatekeeperRRQ & request
01146     );
01147 
01153     virtual H323GatekeeperRequest::Response OnUnregistration(
01154       H323GatekeeperURQ & request
01155     );
01156 
01161     virtual H323GatekeeperRequest::Response OnInfoResponse(
01162       H323GatekeeperIRR & request
01163     );
01164 
01175     virtual void AddEndPoint(
01176       H323RegisteredEndPoint * ep
01177     );
01178 
01181     virtual PBoolean RemoveEndPoint(
01182       H323RegisteredEndPoint * ep
01183     );
01184 
01193     virtual H323RegisteredEndPoint * CreateRegisteredEndPoint(
01194       H323GatekeeperRRQ & request
01195     );
01196 
01205     virtual PString CreateEndPointIdentifier();
01206 
01209     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByIdentifier(
01210       const PString & identifier,
01211       PSafetyMode mode = PSafeReference
01212     );
01213 
01216     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointBySignalAddresses(
01217       const H225_ArrayOf_TransportAddress & addresses,
01218       PSafetyMode mode = PSafeReference
01219     );
01220 
01223     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointBySignalAddress(
01224       const H323TransportAddress & address,
01225       PSafetyMode mode = PSafeReference
01226     );
01227 
01230     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByAliasAddress(
01231       const H225_AliasAddress & alias,
01232       PSafetyMode mode = PSafeReadWrite
01233     );
01234 
01237     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByAliasString(
01238       const PString & alias,
01239       PSafetyMode mode = PSafeReference
01240     );
01241 
01244     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByPartialAlias(
01245       const PString & alias,
01246       PSafetyMode mode = PSafeReference
01247     );
01248 
01251     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByPrefixString(
01252       const PString & prefix,
01253       PSafetyMode mode = PSafeReference
01254     );
01255 
01258     PSafePtr<H323RegisteredEndPoint> GetFirstEndPoint(
01259       PSafetyMode mode = PSafeReference
01260     ) { return PSafePtr<H323RegisteredEndPoint>(byIdentifier, mode); }
01262 
01263     PSafePtr<H323RegisteredEndPoint> FindDestinationEndPoint(
01264       const OpalGloballyUniqueID & id, 
01265       H323GatekeeperCall::Direction direction
01266     );
01267     
01275     virtual H323GatekeeperRequest::Response OnAdmission(
01276       H323GatekeeperARQ & request
01277     );
01278 
01283     virtual H323GatekeeperRequest::Response OnDisengage(
01284       H323GatekeeperDRQ & request
01285     );
01286 
01291     virtual H323GatekeeperRequest::Response OnBandwidth(
01292       H323GatekeeperBRQ & request
01293     );
01294 
01303     virtual H323GatekeeperCall * CreateCall(
01304       const OpalGloballyUniqueID & callIdentifier,
01305       H323GatekeeperCall::Direction direction
01306     );
01307 
01310     virtual void AddCall(H323GatekeeperCall *) 
01311     { }
01312 
01315     virtual void RemoveCall(
01316       H323GatekeeperCall * call
01317     );
01318 
01321     virtual PSafePtr<H323GatekeeperCall> FindCall(
01322       const PString & description,
01323       PSafetyMode mode = PSafeReference
01324     );
01325 
01328     virtual PSafePtr<H323GatekeeperCall> FindCall(
01329       const OpalGloballyUniqueID & callIdentifier,
01330       PBoolean answeringCall,
01331       PSafetyMode mode = PSafeReference
01332     );
01333 
01336     virtual PSafePtr<H323GatekeeperCall> FindCall(
01337       const OpalGloballyUniqueID & callIdentifier,
01338       H323GatekeeperCall::Direction direction,
01339       PSafetyMode mode = PSafeReference
01340     );
01341 
01344     PSafePtr<H323GatekeeperCall> GetFirstCall(
01345       PSafetyMode mode = PSafeReference
01346     ) { return PSafePtr<H323GatekeeperCall>(activeCalls, mode); }
01348 
01358     virtual H323GatekeeperRequest::Response OnLocation(
01359       H323GatekeeperLRQ & request
01360     );
01361 
01373     virtual PBoolean TranslateAliasAddress(
01374       const H225_AliasAddress & alias,
01375       H225_ArrayOf_AliasAddress & aliases,
01376       H323TransportAddress & address,
01377       PBoolean & isGkRouted,
01378       H323GatekeeperCall * call
01379     );
01380 
01400     virtual PBoolean TranslateAliasAddressToSignalAddress(
01401       const H225_AliasAddress & alias,
01402       H323TransportAddress & address
01403     );
01405 
01417     virtual PBoolean CheckSignalAddressPolicy(
01418       const H323RegisteredEndPoint & ep,
01419       const H225_AdmissionRequest & arq,
01420       const H323TransportAddress & address
01421     );
01422 
01435     virtual PBoolean CheckAliasAddressPolicy(
01436       const H323RegisteredEndPoint & ep,
01437       const H225_AdmissionRequest & arq,
01438       const H225_AliasAddress & alias
01439     );
01440 
01453     virtual PBoolean CheckAliasStringPolicy(
01454       const H323RegisteredEndPoint & ep,
01455       const H225_AdmissionRequest & arq,
01456       const PString & alias
01457     );
01458 
01464     virtual unsigned AllocateBandwidth(
01465       unsigned newBandwidth,
01466       unsigned oldBandwidth = 0
01467     );
01469 
01481     virtual PBoolean GetAdmissionRequestAuthentication(
01482       H323GatekeeperARQ & info,           
01483       H235Authenticators & authenticators 
01484     );
01485 
01491     virtual PBoolean GetUsersPassword(
01492       const PString & alias,
01493       PString & password,
01494       H323RegisteredEndPoint & registeredEndpoint
01495     ) const;
01496     virtual PBoolean GetUsersPassword(
01497       const PString & alias,
01498       PString & password
01499     ) const;
01501 
01506     H323PeerElement * GetPeerElement() const { return peerElement; }
01507 
01511     void SetPeerElement(
01512       H323PeerElement * newPeerElement
01513     );
01514 
01520     void CreatePeerElement(
01521       const H323TransportAddress & h501Interface
01522     );
01523 
01529     PBoolean OpenPeerElement(
01530       const H323TransportAddress & remotePeer,
01531       PBoolean append = PFalse,
01532       PBoolean keepTrying = PTrue
01533     );
01535 
01540     const PString & GetGatekeeperIdentifier() const { return gatekeeperIdentifier; }
01541 
01547     void SetGatekeeperIdentifier(
01548       const PString & id,
01549       PBoolean adjustListeners = PTrue
01550     );
01551 
01554     unsigned GetAvailableBandwidth() const { return totalBandwidth; }
01555 
01558     void SetAvailableBandwidth(unsigned bps100) { totalBandwidth = bps100; }
01559 
01562     unsigned GetUsedBandwidth() const { return usedBandwidth; }
01563 
01566     unsigned GetDefaultBandwidth() const { return defaultBandwidth; }
01567 
01570     unsigned GetTimeToLive() const { return defaultTimeToLive; }
01571 
01574     void SetTimeToLive(unsigned seconds) { defaultTimeToLive = seconds; }
01575 
01578     unsigned GetInfoResponseRate() const { return defaultInfoResponseRate; }
01579 
01582     void SetInfoResponseRate(unsigned seconds) { defaultInfoResponseRate = seconds; }
01583 
01586     PBoolean IsGatekeeperRouted() const { return isGatekeeperRouted; }
01587 
01590     PBoolean IsRequiredH235() const { return requireH235; }
01591 
01594     unsigned GetActiveRegistrations() const { return byIdentifier.GetSize(); }
01595 
01598     unsigned GetPeakRegistrations() const { return peakRegistrations; }
01599 
01602     unsigned GetTotalRegistrations() const { return totalRegistrations; }
01603 
01606     unsigned GetRejectedRegistrations() const { return rejectedRegistrations; }
01607 
01610     unsigned GetActiveCalls() const { return activeCalls.GetSize(); }
01611 
01614     unsigned GetPeakCalls() const { return peakCalls; }
01615 
01618     unsigned GetTotalCalls() const { return totalCalls; }
01619 
01622     unsigned GetRejectedCalls() const { return rejectedCalls; }
01624 
01625     // Remove an alias from the server database.
01626     void RemoveAlias(
01627       H323RegisteredEndPoint & ep,
01628       const PString & alias
01629     );
01630 
01631     // called when an endpoint needs to send a descriptor to the H.501 peer element
01632     virtual PBoolean OnSendDescriptorForEndpoint(
01633       H323RegisteredEndPoint & /*ep*/,                    
01634       H225_ArrayOf_AliasAddress & /*aliases*/,            
01635       H225_EndpointType & /*terminalType*/,               
01636       H225_ArrayOf_AliasAddress & /*transportAddresses*/  
01637     )
01638     { return PTrue; } 
01639 
01640     virtual PBoolean AllowDuplicateAlias(const H225_ArrayOf_AliasAddress & /*aliases*/)
01641     { return canHaveDuplicateAlias; }
01642 
01643     virtual PBoolean OnSendFeatureSet(unsigned, H225_FeatureSet & features) const;
01644     virtual void OnReceiveFeatureSet(unsigned, const H225_FeatureSet & features) const;
01645 
01646   protected:
01647 
01648     PDECLARE_NOTIFIER(PThread, H323GatekeeperServer, MonitorMain);
01649 
01650     // Configuration & policy variables
01651     PString  gatekeeperIdentifier;
01652     unsigned totalBandwidth;
01653     unsigned usedBandwidth;
01654     unsigned defaultBandwidth;
01655     unsigned maximumBandwidth;
01656     unsigned defaultTimeToLive;
01657     unsigned defaultInfoResponseRate;
01658     PBoolean     overwriteOnSameSignalAddress;
01659     PBoolean     canHaveDuplicateAlias;
01660     PBoolean     canHaveDuplicatePrefix;
01661     PBoolean     canOnlyCallRegisteredEP;
01662     PBoolean     canOnlyAnswerRegisteredEP;
01663     PBoolean     answerCallPreGrantedARQ;
01664     PBoolean     makeCallPreGrantedARQ;
01665     PBoolean     isGatekeeperRouted;
01666     PBoolean     aliasCanBeHostName;
01667     PBoolean     requireH235;
01668     PBoolean     disengageOnHearbeatFail;
01669 
01670     PStringToString passwords;
01671 
01672     // Dynamic variables
01673     PMutex         mutex;
01674     time_t         identifierBase;
01675     unsigned       nextIdentifier;
01676     PThread      * monitorThread;
01677     PSyncPoint     monitorExit;
01678 
01679     PLIST(ListenerList, H323GatekeeperListener);
01680     ListenerList listeners;
01681 
01682     H323PeerElement * peerElement;
01683 
01684     PSafeDictionary<PString, H323RegisteredEndPoint> byIdentifier;
01685 
01686     class StringMap : public PString {
01687         PCLASSINFO(StringMap, PString);
01688       public:
01689         StringMap(const PString & from, const PString & id)
01690           : PString(from), identifier(id) { }
01691         PString identifier;
01692     };
01693     PSortedStringList byAddress;
01694     PSortedStringList byAlias;
01695     PSortedStringList byVoicePrefix;
01696 
01697     PSafeSortedList<H323GatekeeperCall> activeCalls;
01698 
01699     PINDEX peakRegistrations;
01700     PINDEX totalRegistrations;
01701     PINDEX rejectedRegistrations;
01702     PINDEX peakCalls;
01703     PINDEX totalCalls;
01704     PINDEX rejectedCalls;
01705 
01706   friend class H323GatekeeperRRQ;
01707   friend class H323GatekeeperARQ;
01708 };
01709 
01710 
01711 #endif // __OPAL_GKSERVER_H
01712 
01713 
01715 

Generated on Mon Sep 15 11:48:45 2008 for OPAL by  doxygen 1.5.1