00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 #ifndef OPAL_H323_GKSERVER_H
00035 #define OPAL_H323_GKSERVER_H
00036 
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040 
00041 #include <opal/buildopts.h>
00042 
00043 #if OPAL_H323
00044 
00045 #include <ptlib/safecoll.h>
00046 #include <opal/guid.h>
00047 #include <h323/h225ras.h>
00048 #include <h323/transaddr.h>
00049 #include <h323/h235auth.h>
00050 #include <h323/h323pdu.h>
00051 #include <h323/h323trans.h>
00052 
00053 
00054 class PASN_Sequence;
00055 class PASN_Choice;
00056 
00057 class H225_AliasAddress;
00058 class H225_EndpointIdentifier;
00059 class H225_GatekeeperIdentifier;
00060 class H225_ArrayOf_TransportAddress;
00061 class H225_GatekeeperIdentifier;
00062 class H225_EndpointIdentifier;
00063 class H225_InfoRequestResponse_perCallInfo_subtype;
00064 class H225_RasUsageInformation;
00065 
00066 class H323RegisteredEndPoint;
00067 class H323GatekeeperListener;
00068 class H323GatekeeperServer;
00069 class H323RasPDU;
00070 
00071 #if OPAL_H501
00072 class H323PeerElement;
00073 #endif
00074 
00075 class H323GatekeeperRequest : public H323Transaction
00076 {
00077     PCLASSINFO(H323GatekeeperRequest, H323Transaction);
00078   public:
00083     H323GatekeeperRequest(
00084       H323GatekeeperListener & rasChannel,
00085       const H323RasPDU & pdu
00086     );
00088 
00089     virtual H323TransactionPDU * CreateRIP(
00090       unsigned sequenceNumber,
00091       unsigned delay
00092     ) const;
00093 
00094     virtual PBoolean WritePDU(
00095       H323TransactionPDU & pdu
00096     );
00097     PBoolean CheckCryptoTokens();
00098     PBoolean CheckGatekeeperIdentifier();
00099     PBoolean GetRegisteredEndPoint();
00100 
00101     virtual PString GetGatekeeperIdentifier() const = 0;
00102     virtual unsigned GetGatekeeperRejectTag() const = 0;
00103     virtual PString GetEndpointIdentifier() const = 0;
00104     virtual unsigned GetRegisteredEndPointRejectTag() const = 0;
00105     virtual unsigned GetSecurityRejectTag() const = 0;
00106 
00107     H323GatekeeperListener & GetRasChannel() const { return rasChannel; }
00108 
00109     PSafePtr<H323RegisteredEndPoint> endpoint;
00110 
00111   protected:
00112     H323GatekeeperListener & rasChannel;
00113 };
00114 
00115 
00116 class H323GatekeeperGRQ : public H323GatekeeperRequest
00117 {
00118     PCLASSINFO(H323GatekeeperGRQ, H323GatekeeperRequest);
00119   public:
00120     H323GatekeeperGRQ(
00121       H323GatekeeperListener & listener,
00122       const H323RasPDU & pdu
00123     );
00124 
00125 #if PTRACING
00126     virtual const char * GetName() const;
00127 #endif
00128     virtual PString GetGatekeeperIdentifier() const;
00129     virtual unsigned GetGatekeeperRejectTag() const;
00130     virtual PString GetEndpointIdentifier() const;
00131     virtual unsigned GetRegisteredEndPointRejectTag() const;
00132     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00133     virtual unsigned GetSecurityRejectTag() const;
00134     virtual void SetRejectReason(
00135       unsigned reasonCode
00136     );
00137 
00138     H225_GatekeeperRequest & grq;
00139     H225_GatekeeperConfirm & gcf;
00140     H225_GatekeeperReject  & grj;
00141 
00142   protected:
00143     virtual Response OnHandlePDU();
00144 };
00145 
00146 
00147 class H323GatekeeperRRQ : public H323GatekeeperRequest
00148 {
00149     PCLASSINFO(H323GatekeeperRRQ, H323GatekeeperRequest);
00150   public:
00151     H323GatekeeperRRQ(
00152       H323GatekeeperListener & listener,
00153       const H323RasPDU & pdu
00154     );
00155 
00156 #if PTRACING
00157     virtual const char * GetName() const;
00158 #endif
00159     virtual PString GetGatekeeperIdentifier() const;
00160     virtual unsigned GetGatekeeperRejectTag() const;
00161     virtual PString GetEndpointIdentifier() const;
00162     virtual unsigned GetRegisteredEndPointRejectTag() const;
00163     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00164     virtual unsigned GetSecurityRejectTag() const;
00165     virtual void SetRejectReason(
00166       unsigned reasonCode
00167     );
00168 
00169     H225_RegistrationRequest & rrq;
00170     H225_RegistrationConfirm & rcf;
00171     H225_RegistrationReject  & rrj;
00172 
00173   protected:
00174     virtual Response OnHandlePDU();
00175 };
00176 
00177 
00178 class H323GatekeeperURQ : public H323GatekeeperRequest
00179 {
00180     PCLASSINFO(H323GatekeeperURQ, H323GatekeeperRequest);
00181   public:
00182     H323GatekeeperURQ(
00183       H323GatekeeperListener & listener,
00184       const H323RasPDU & pdu
00185     );
00186 
00187 #if PTRACING
00188     virtual const char * GetName() const;
00189 #endif
00190     virtual PString GetGatekeeperIdentifier() const;
00191     virtual unsigned GetGatekeeperRejectTag() const;
00192     virtual PString GetEndpointIdentifier() const;
00193     virtual unsigned GetRegisteredEndPointRejectTag() const;
00194     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00195     virtual unsigned GetSecurityRejectTag() const;
00196     virtual void SetRejectReason(
00197       unsigned reasonCode
00198     );
00199 
00200     H225_UnregistrationRequest & urq;
00201     H225_UnregistrationConfirm & ucf;
00202     H225_UnregistrationReject  & urj;
00203 
00204   protected:
00205     virtual Response OnHandlePDU();
00206 };
00207 
00208 
00209 class H323GatekeeperARQ : public H323GatekeeperRequest
00210 {
00211     PCLASSINFO(H323GatekeeperARQ, H323GatekeeperRequest);
00212   public:
00213     H323GatekeeperARQ(
00214       H323GatekeeperListener & listener,
00215       const H323RasPDU & pdu
00216     );
00217 
00218 #if PTRACING
00219     virtual const char * GetName() const;
00220 #endif
00221     virtual PString GetGatekeeperIdentifier() const;
00222     virtual unsigned GetGatekeeperRejectTag() const;
00223     virtual PString GetEndpointIdentifier() const;
00224     virtual unsigned GetRegisteredEndPointRejectTag() const;
00225     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00226     virtual unsigned GetSecurityRejectTag() const;
00227     virtual void SetRejectReason(
00228       unsigned reasonCode
00229     );
00230 
00231     H225_AdmissionRequest & arq;
00232     H225_AdmissionConfirm & acf;
00233     H225_AdmissionReject  & arj;
00234 
00235     PString alternateSecurityID;
00236 
00237   protected:
00238     virtual Response OnHandlePDU();
00239 };
00240 
00241 
00242 class H323GatekeeperDRQ : public H323GatekeeperRequest
00243 {
00244     PCLASSINFO(H323GatekeeperDRQ, H323GatekeeperRequest);
00245   public:
00246     H323GatekeeperDRQ(
00247       H323GatekeeperListener & listener,
00248       const H323RasPDU & pdu
00249     );
00250 
00251 #if PTRACING
00252     virtual const char * GetName() const;
00253 #endif
00254     virtual PString GetGatekeeperIdentifier() const;
00255     virtual unsigned GetGatekeeperRejectTag() const;
00256     virtual PString GetEndpointIdentifier() const;
00257     virtual unsigned GetRegisteredEndPointRejectTag() const;
00258     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00259     virtual unsigned GetSecurityRejectTag() const;
00260     virtual void SetRejectReason(
00261       unsigned reasonCode
00262     );
00263 
00264     H225_DisengageRequest & drq;
00265     H225_DisengageConfirm & dcf;
00266     H225_DisengageReject  & drj;
00267 
00268   protected:
00269     virtual Response OnHandlePDU();
00270 };
00271 
00272 
00273 class H323GatekeeperBRQ : public H323GatekeeperRequest
00274 {
00275     PCLASSINFO(H323GatekeeperBRQ, H323GatekeeperRequest);
00276   public:
00277     H323GatekeeperBRQ(
00278       H323GatekeeperListener & listener,
00279       const H323RasPDU & pdu
00280     );
00281 
00282 #if PTRACING
00283     virtual const char * GetName() const;
00284 #endif
00285     virtual PString GetGatekeeperIdentifier() const;
00286     virtual unsigned GetGatekeeperRejectTag() const;
00287     virtual PString GetEndpointIdentifier() const;
00288     virtual unsigned GetRegisteredEndPointRejectTag() const;
00289     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00290     virtual unsigned GetSecurityRejectTag() const;
00291     virtual void SetRejectReason(
00292       unsigned reasonCode
00293     );
00294 
00295     H225_BandwidthRequest & brq;
00296     H225_BandwidthConfirm & bcf;
00297     H225_BandwidthReject  & brj;
00298 
00299   protected:
00300     virtual Response OnHandlePDU();
00301 };
00302 
00303 
00304 class H323GatekeeperLRQ : public H323GatekeeperRequest
00305 {
00306     PCLASSINFO(H323GatekeeperLRQ, H323GatekeeperRequest);
00307   public:
00308     H323GatekeeperLRQ(
00309       H323GatekeeperListener & listener,
00310       const H323RasPDU & pdu
00311     );
00312 
00313 #if PTRACING
00314     virtual const char * GetName() const;
00315 #endif
00316     virtual PString GetGatekeeperIdentifier() const;
00317     virtual unsigned GetGatekeeperRejectTag() const;
00318     virtual PString GetEndpointIdentifier() const;
00319     virtual unsigned GetRegisteredEndPointRejectTag() const;
00320     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00321     virtual unsigned GetSecurityRejectTag() const;
00322     virtual void SetRejectReason(
00323       unsigned reasonCode
00324     );
00325 
00326     H225_LocationRequest & lrq;
00327     H225_LocationConfirm & lcf;
00328     H225_LocationReject  & lrj;
00329 
00330   protected:
00331     virtual Response OnHandlePDU();
00332 };
00333 
00334 
00335 class H323GatekeeperIRR : public H323GatekeeperRequest
00336 {
00337     PCLASSINFO(H323GatekeeperIRR, H323GatekeeperRequest);
00338   public:
00339     H323GatekeeperIRR(
00340       H323GatekeeperListener & listener,
00341       const H323RasPDU & pdu
00342     );
00343 
00344 #if PTRACING
00345     virtual const char * GetName() const;
00346 #endif
00347     virtual PString GetGatekeeperIdentifier() const;
00348     virtual unsigned GetGatekeeperRejectTag() const;
00349     virtual PString GetEndpointIdentifier() const;
00350     virtual unsigned GetRegisteredEndPointRejectTag() const;
00351     virtual H235Authenticator::ValidationResult ValidatePDU() const;
00352     virtual unsigned GetSecurityRejectTag() const;
00353     virtual void SetRejectReason(
00354       unsigned reasonCode
00355     );
00356 
00357     H225_InfoRequestResponse & irr;
00358     H225_InfoRequestAck      & iack;
00359     H225_InfoRequestNak      & inak;
00360 
00361   protected:
00362     virtual Response OnHandlePDU();
00363 };
00364 
00365 
00368 class H323GatekeeperCall : public PSafeObject
00369 {
00370     PCLASSINFO(H323GatekeeperCall, PSafeObject);
00371   public:
00374     enum Direction {
00375       AnsweringCall,
00376       OriginatingCall,
00377       UnknownDirection
00378     };
00379 
00382     H323GatekeeperCall(
00383       H323GatekeeperServer & server,               
00384       const OpalGloballyUniqueID & callIdentifier, 
00385       Direction direction                          
00386     );
00387 
00390     ~H323GatekeeperCall();
00392 
00397     Comparison Compare(
00398       const PObject & obj  
00399     ) const;
00400 
00403     void PrintOn(
00404       ostream & strm    
00405     ) const;
00407 
00415     virtual H323GatekeeperRequest::Response OnAdmission(
00416       H323GatekeeperARQ & request
00417     );
00418 
00422     virtual PBoolean Disengage(
00423       int reason = -1   
00424     );
00425 
00429     virtual H323GatekeeperRequest::Response OnDisengage(
00430       H323GatekeeperDRQ & request
00431     );
00432 
00437     virtual H323GatekeeperRequest::Response OnBandwidth(
00438       H323GatekeeperBRQ & request
00439     );
00440 
00444     virtual H323GatekeeperRequest::Response OnInfoResponse(
00445       H323GatekeeperIRR & request,
00446       H225_InfoRequestResponse_perCallInfo_subtype & call
00447     );
00448 
00451     virtual void OnAlerting();
00452 
00455     virtual void OnConnected();
00456 
00467     virtual PBoolean OnHeartbeat();
00468 
00475     virtual PString GetCallCreditAmount() const;
00476 
00483     virtual PBoolean GetCallCreditMode() const;
00484 
00492     virtual unsigned GetDurationLimit() const;
00493 
00498     virtual PBoolean SendCallCreditServiceControl();
00499 
00502     PBoolean AddCallCreditServiceControl(
00503       H225_ArrayOf_ServiceControlSession & serviceControl
00504     ) const;
00505 
00510     virtual PBoolean SendServiceControlSession(
00511       const H323ServiceControlSession & session
00512     );
00513 
00519     virtual PBoolean TranslateAliasAddress(
00520       const H225_AliasAddress & alias,
00521       H225_ArrayOf_AliasAddress & aliases,
00522       H323TransportAddress & address,
00523       PBoolean & isGkRouted
00524     );
00525 
00527 
00530     H323GatekeeperServer & GetGatekeeper() const { return gatekeeper; }
00531     H323RegisteredEndPoint & GetEndPoint() const { return *PAssertNULL(endpoint); }
00532     PBoolean IsAnsweringCall() const { return direction == AnsweringCall; }
00533     unsigned GetCallReference() const { return callReference; }
00534     const OpalGloballyUniqueID & GetCallIdentifier() const { return callIdentifier; }
00535     const OpalGloballyUniqueID & GetConferenceIdentifier() const { return conferenceIdentifier; }
00536     const PString & GetSourceNumber() const { return srcNumber; }
00537     const PStringArray & GetSourceAliases() const { return srcAliases; }
00538     const H323TransportAddress & GetSourceHost() const { return srcHost; }
00539     PString GetSourceAddress() const;
00540     const PString & GetDestinationNumber() const { return dstNumber; }
00541     const PStringArray & GetDestinationAliases() const { return dstAliases; }
00542     const H323TransportAddress & GetDestinationHost() const { return dstHost; }
00543     PString GetDestinationAddress() const;
00544     unsigned GetBandwidthUsed() const { return bandwidthUsed; }
00545     PBoolean SetBandwidthUsed(unsigned bandwidth);
00546     const PTime & GetLastInfoResponseTime() const { return lastInfoResponse; }
00547     const PTime & GetCallStartTime() const { return callStartTime; }
00548     const PTime & GetAlertingTime() const { return alertingTime; }
00549     const PTime & GetConnectedTime() const { return connectedTime; }
00550     const PTime & GetCallEndTime() const { return callEndTime; }
00551     H323Connection::CallEndReason GetCallEndReason() const { return callEndReason; }
00553 
00554   protected:
00555     void SetUsageInfo(const H225_RasUsageInformation & usage);
00556 
00557     H323GatekeeperServer   & gatekeeper;
00558     H323RegisteredEndPoint * endpoint;
00559     H323GatekeeperListener * rasChannel;
00560 
00561     Direction            direction;
00562     unsigned             callReference;
00563     OpalGloballyUniqueID callIdentifier;
00564     OpalGloballyUniqueID conferenceIdentifier;
00565     PString              srcNumber;
00566     PStringArray         srcAliases;
00567     H323TransportAddress srcHost;
00568     PString              dstNumber;
00569     PStringArray         dstAliases;
00570     H323TransportAddress dstHost;
00571     unsigned             bandwidthUsed;
00572     unsigned             infoResponseRate;
00573     PTime                lastInfoResponse;
00574 
00575     PBoolean                          drqReceived;
00576     PTime                         callStartTime;
00577     PTime                         alertingTime;
00578     PTime                         connectedTime;
00579     PTime                         callEndTime;
00580     H323Connection::CallEndReason callEndReason;
00581 };
00582 
00583 
00589 class H323RegisteredEndPoint : public PSafeObject
00590 {
00591     PCLASSINFO(H323RegisteredEndPoint, PSafeObject);
00592   public:
00597     H323RegisteredEndPoint(
00598       H323GatekeeperServer & server, 
00599       const PString & id             
00600     );
00602 
00607     Comparison Compare(
00608       const PObject & obj  
00609     ) const;
00610 
00613     void PrintOn(
00614       ostream & strm    
00615     ) const;
00617 
00624     virtual void AddCall(
00625       H323GatekeeperCall * call
00626     );
00627 
00632     virtual PBoolean RemoveCall(
00633       H323GatekeeperCall * call
00634     );
00635 
00638     PINDEX GetCallCount() const { return activeCalls.GetSize(); }
00639 
00642     H323GatekeeperCall & GetCall(
00643       PINDEX idx
00644     ) { return activeCalls[idx]; }
00646 
00655     virtual H323GatekeeperRequest::Response OnRegistration(
00656       H323GatekeeperRRQ & request
00657     );
00658 
00668     virtual H323GatekeeperRequest::Response OnFullRegistration(
00669       H323GatekeeperRRQ & request
00670     );
00671 
00680     virtual H323GatekeeperRequest::Response OnSecureRegistration(
00681       H323GatekeeperRRQ & request
00682     );
00683 
00687     virtual H323GatekeeperRequest::Response OnUnregistration(
00688       H323GatekeeperURQ & request
00689     );
00690 
00694     virtual PBoolean Unregister(
00695       int reason = -1   
00696     );
00697 
00702     virtual H323GatekeeperRequest::Response OnInfoResponse(
00703       H323GatekeeperIRR & request
00704     );
00705 
00716     virtual PBoolean OnTimeToLive();
00717 
00729     virtual PString GetCallCreditAmount() const;
00730 
00738     virtual PBoolean GetCallCreditMode() const;
00739 
00744     virtual PBoolean SendServiceControlSession(
00745       const H323ServiceControlSession & session
00746     );
00747 
00751     virtual PBoolean AddServiceControlSession(
00752       const H323ServiceControlSession & session,
00753       H225_ArrayOf_ServiceControlSession & serviceControl
00754     );
00756 
00761     virtual PBoolean SetPassword(
00762       const PString & password,
00763       const PString & username = PString::Empty()
00764     );
00765 
00768     const PString & GetIdentifier() const { return identifier; }
00769 
00772     const OpalGloballyUniqueID & GetDescriptorID() const { return descriptorID; }
00773 
00776     H323GatekeeperServer & GetGatekeeper() const { return gatekeeper; }
00777 
00781     const H323TransportAddressArray & GetRASAddresses() const { return rasAddresses; }
00782 
00786     PINDEX GetRASAddressCount() const { return rasAddresses.GetSize(); }
00787 
00791     H323TransportAddress GetRASAddress(
00792       PINDEX idx
00793     ) const { return rasAddresses[idx]; }
00794 
00798     const H323TransportAddressArray & GetSignalAddresses() const { return signalAddresses; }
00799 
00803     PINDEX GetSignalAddressCount() const { return signalAddresses.GetSize(); }
00804 
00808     H323TransportAddress GetSignalAddress(
00809       PINDEX idx
00810     ) const { return signalAddresses[idx]; }
00811 
00814     const PStringArray & GetAliases() const { return aliases; }
00815 
00818     PBoolean ContainsAlias(
00819       const PString & alias
00820       ) { return aliases.GetStringsIndex(alias) != P_MAX_INDEX; }
00821 
00824     PINDEX GetAliasCount() const { return aliases.GetSize(); }
00825 
00828     PString GetAlias(
00829       PINDEX idx
00830     ) const { if (idx < aliases.GetSize()) return aliases[idx]; return PString::Empty(); }
00831 
00837     void RemoveAlias(
00838       const PString & alias
00839     );
00840 
00843     virtual const H235Authenticators & GetAuthenticators() const { return authenticators; }
00844 
00847     PINDEX GetPrefixCount() const { return voicePrefixes.GetSize(); }
00848 
00851     PString GetPrefix(
00852       PINDEX idx
00853     ) const { return voicePrefixes[idx]; }
00854 
00857     PCaselessString GetApplicationInfo() const { return productInfo.AsString(); }
00858 
00861     const OpalProductInfo & GetProductInfo() const { return productInfo; }
00862 
00865     unsigned GetProtocolVersion() const { return protocolVersion; }
00866 
00869     PBoolean IsBehindNAT() const { return isBehindNAT; }
00870 
00873     PBoolean CanDisplayAmountString() const { return canDisplayAmountString; }
00874 
00877     PBoolean CanEnforceDurationLimit() const { return canEnforceDurationLimit; }
00878 
00881     PBoolean CanReceiveRIP() const;
00882 
00885     PBoolean GetH225Version() const { return h225Version; }
00887 
00897       virtual PBoolean OnSendDescriptorForEndpoint(
00898         H225_ArrayOf_AliasAddress & aliases,          
00899         H225_EndpointType & terminalType,             
00900         H225_ArrayOf_AliasAddress & transportAddresses  
00901       );
00903 
00904 
00905   protected:
00906     H323GatekeeperServer    & gatekeeper;
00907     H323GatekeeperListener  * rasChannel;
00908 
00909     PString                   identifier;
00910     OpalGloballyUniqueID      descriptorID;
00911     H323TransportAddressArray rasAddresses;
00912     H323TransportAddressArray signalAddresses;
00913     PStringArray              aliases;
00914     PStringArray              voicePrefixes;
00915     OpalProductInfo           productInfo;
00916     unsigned                  protocolVersion;
00917     PBoolean                      isBehindNAT;
00918     PBoolean                      canDisplayAmountString;
00919     PBoolean                      canEnforceDurationLimit;
00920     unsigned                  h225Version;
00921     unsigned                  timeToLive;
00922     H235Authenticators        authenticators;
00923 
00924     PTime lastRegistration;
00925     PTime lastInfoResponse;
00926 
00927     PSortedList<H323GatekeeperCall> activeCalls;
00928     POrdinalDictionary<PString>     serviceControlSessions;
00929 };
00930 
00931 
00937 class H323GatekeeperListener : public H225_RAS
00938 {
00939     PCLASSINFO(H323GatekeeperListener, H225_RAS);
00940   public:
00945     H323GatekeeperListener(
00946       H323EndPoint & endpoint,               
00947       H323GatekeeperServer & server,         
00948       const PString & gatekeeperIdentifier,  
00949       H323Transport * transport = NULL       
00950     );
00951 
00954     ~H323GatekeeperListener();
00956 
00961     PBoolean UnregistrationRequest(
00962       const H323RegisteredEndPoint & ep,
00963       unsigned reason
00964     );
00965 
00968     PBoolean DisengageRequest(
00969       const H323GatekeeperCall & call,
00970       unsigned reason
00971     );
00972 
00975     virtual PBoolean InfoRequest(
00976       H323RegisteredEndPoint & ep,
00977       H323GatekeeperCall * call = NULL
00978     );
00979 
00982     virtual PBoolean ServiceControlIndication(
00983       H323RegisteredEndPoint & ep,
00984       const H323ServiceControlSession & session,
00985       H323GatekeeperCall * call = NULL
00986     );
00988 
00995     virtual H323GatekeeperRequest::Response OnDiscovery(
00996       H323GatekeeperGRQ & request
00997     );
00998 
01003     virtual H323GatekeeperRequest::Response OnRegistration(
01004       H323GatekeeperRRQ & request
01005     );
01006 
01011     virtual H323GatekeeperRequest::Response OnUnregistration(
01012       H323GatekeeperURQ & request
01013     );
01014 
01019     virtual H323GatekeeperRequest::Response OnAdmission(
01020       H323GatekeeperARQ & request
01021     );
01022 
01027     virtual H323GatekeeperRequest::Response OnDisengage(
01028       H323GatekeeperDRQ & request
01029     );
01030 
01035     virtual H323GatekeeperRequest::Response OnBandwidth(
01036       H323GatekeeperBRQ & request
01037     );
01038 
01043     virtual H323GatekeeperRequest::Response OnLocation(
01044       H323GatekeeperLRQ & request
01045     );
01046 
01051     virtual H323GatekeeperRequest::Response OnInfoResponse(
01052       H323GatekeeperIRR & request
01053     );
01055 
01058     virtual PBoolean OnReceiveGatekeeperRequest(const H323RasPDU &, const H225_GatekeeperRequest &);
01059     virtual PBoolean OnReceiveRegistrationRequest(const H323RasPDU &, const H225_RegistrationRequest &);
01060     virtual PBoolean OnReceiveUnregistrationRequest(const H323RasPDU &, const H225_UnregistrationRequest &);
01061     virtual PBoolean OnReceiveUnregistrationConfirm(const H225_UnregistrationConfirm &);
01062     virtual PBoolean OnReceiveUnregistrationReject(const H225_UnregistrationReject &);
01063     virtual PBoolean OnReceiveAdmissionRequest(const H323RasPDU &, const H225_AdmissionRequest &);
01064     virtual PBoolean OnReceiveBandwidthRequest(const H323RasPDU &, const H225_BandwidthRequest &);
01065     virtual PBoolean OnReceiveBandwidthConfirm(const H225_BandwidthConfirm &);
01066     virtual PBoolean OnReceiveBandwidthReject(const H225_BandwidthReject &);
01067     virtual PBoolean OnReceiveDisengageRequest(const H323RasPDU &, const H225_DisengageRequest &);
01068     virtual PBoolean OnReceiveDisengageConfirm(const H225_DisengageConfirm &);
01069     virtual PBoolean OnReceiveDisengageReject(const H225_DisengageReject &);
01070     virtual PBoolean OnReceiveLocationRequest(const H323RasPDU &, const H225_LocationRequest &);
01071     virtual PBoolean OnReceiveInfoRequestResponse(const H323RasPDU &, const H225_InfoRequestResponse &);
01072     virtual PBoolean OnReceiveResourcesAvailableConfirm(const H225_ResourcesAvailableConfirm &);
01073     virtual PBoolean OnSendFeatureSet(unsigned, H225_FeatureSet & features) const;
01074     virtual void OnReceiveFeatureSet(unsigned, const H225_FeatureSet & features) const;
01076 
01079     H323GatekeeperServer & GetGatekeeper() const { return gatekeeper; }
01081 
01082 
01083   protected:
01084     H323GatekeeperServer & gatekeeper;
01085 };
01086 
01087 
01098 class H323GatekeeperServer : public H323TransactionServer
01099 {
01100     PCLASSINFO(H323GatekeeperServer, H323TransactionServer);
01101   public:
01106     H323GatekeeperServer(
01107       H323EndPoint & endpoint
01108     );
01109 
01112     ~H323GatekeeperServer();
01114 
01115     WORD GetDefaultUdpPort() { return H225_RAS::DefaultRasUdpPort; }
01116 
01127     virtual H323Transactor * CreateListener(
01128       H323Transport * transport  
01129     );
01130 
01132 
01138     virtual H323GatekeeperRequest::Response OnDiscovery(
01139       H323GatekeeperGRQ & request
01140     );
01141 
01149     virtual H323GatekeeperRequest::Response OnRegistration(
01150       H323GatekeeperRRQ & request
01151     );
01152 
01158     virtual H323GatekeeperRequest::Response OnUnregistration(
01159       H323GatekeeperURQ & request
01160     );
01161 
01166     virtual H323GatekeeperRequest::Response OnInfoResponse(
01167       H323GatekeeperIRR & request
01168     );
01169 
01180     virtual void AddEndPoint(
01181       H323RegisteredEndPoint * ep
01182     );
01183 
01186     virtual PBoolean RemoveEndPoint(
01187       H323RegisteredEndPoint * ep
01188     );
01189 
01198     virtual H323RegisteredEndPoint * CreateRegisteredEndPoint(
01199       H323GatekeeperRRQ & request
01200     );
01201 
01210     virtual PString CreateEndPointIdentifier();
01211 
01214     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByIdentifier(
01215       const PString & identifier,
01216       PSafetyMode mode = PSafeReference
01217     );
01218 
01221     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointBySignalAddresses(
01222       const H225_ArrayOf_TransportAddress & addresses,
01223       PSafetyMode mode = PSafeReference
01224     );
01225 
01228     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointBySignalAddress(
01229       const H323TransportAddress & address,
01230       PSafetyMode mode = PSafeReference
01231     );
01232 
01235     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByAliasAddress(
01236       const H225_AliasAddress & alias,
01237       PSafetyMode mode = PSafeReadWrite
01238     );
01239 
01242     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByAliasString(
01243       const PString & alias,
01244       PSafetyMode mode = PSafeReference
01245     );
01246 
01249     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByPartialAlias(
01250       const PString & alias,
01251       PSafetyMode mode = PSafeReference
01252     );
01253 
01256     virtual PSafePtr<H323RegisteredEndPoint> FindEndPointByPrefixString(
01257       const PString & prefix,
01258       PSafetyMode mode = PSafeReference
01259     );
01260 
01263     PSafePtr<H323RegisteredEndPoint> GetFirstEndPoint(
01264       PSafetyMode mode = PSafeReference
01265     ) { return PSafePtr<H323RegisteredEndPoint>(byIdentifier, mode); }
01267 
01268     PSafePtr<H323RegisteredEndPoint> FindDestinationEndPoint(
01269       const OpalGloballyUniqueID & id, 
01270       H323GatekeeperCall::Direction direction
01271     );
01272     
01280     virtual H323GatekeeperRequest::Response OnAdmission(
01281       H323GatekeeperARQ & request
01282     );
01283 
01288     virtual H323GatekeeperRequest::Response OnDisengage(
01289       H323GatekeeperDRQ & request
01290     );
01291 
01296     virtual H323GatekeeperRequest::Response OnBandwidth(
01297       H323GatekeeperBRQ & request
01298     );
01299 
01308     virtual H323GatekeeperCall * CreateCall(
01309       const OpalGloballyUniqueID & callIdentifier,
01310       H323GatekeeperCall::Direction direction
01311     );
01312 
01315     virtual void AddCall(H323GatekeeperCall *) 
01316     { }
01317 
01320     virtual void RemoveCall(
01321       H323GatekeeperCall * call
01322     );
01323 
01326     virtual PSafePtr<H323GatekeeperCall> FindCall(
01327       const PString & description,
01328       PSafetyMode mode = PSafeReference
01329     );
01330 
01333     virtual PSafePtr<H323GatekeeperCall> FindCall(
01334       const OpalGloballyUniqueID & callIdentifier,
01335       PBoolean answeringCall,
01336       PSafetyMode mode = PSafeReference
01337     );
01338 
01341     virtual PSafePtr<H323GatekeeperCall> FindCall(
01342       const OpalGloballyUniqueID & callIdentifier,
01343       H323GatekeeperCall::Direction direction,
01344       PSafetyMode mode = PSafeReference
01345     );
01346 
01349     PSafePtr<H323GatekeeperCall> GetFirstCall(
01350       PSafetyMode mode = PSafeReference
01351     ) { return PSafePtr<H323GatekeeperCall>(activeCalls, mode); }
01353 
01363     virtual H323GatekeeperRequest::Response OnLocation(
01364       H323GatekeeperLRQ & request
01365     );
01366 
01378     virtual PBoolean TranslateAliasAddress(
01379       const H225_AliasAddress & alias,
01380       H225_ArrayOf_AliasAddress & aliases,
01381       H323TransportAddress & address,
01382       PBoolean & isGkRouted,
01383       H323GatekeeperCall * call
01384     );
01385 
01405     virtual PBoolean TranslateAliasAddressToSignalAddress(
01406       const H225_AliasAddress & alias,
01407       H323TransportAddress & address
01408     );
01410 
01422     virtual PBoolean CheckSignalAddressPolicy(
01423       const H323RegisteredEndPoint & ep,
01424       const H225_AdmissionRequest & arq,
01425       const H323TransportAddress & address
01426     );
01427 
01440     virtual PBoolean CheckAliasAddressPolicy(
01441       const H323RegisteredEndPoint & ep,
01442       const H225_AdmissionRequest & arq,
01443       const H225_AliasAddress & alias
01444     );
01445 
01458     virtual PBoolean CheckAliasStringPolicy(
01459       const H323RegisteredEndPoint & ep,
01460       const H225_AdmissionRequest & arq,
01461       const PString & alias
01462     );
01463 
01469     virtual unsigned AllocateBandwidth(
01470       unsigned newBandwidth,
01471       unsigned oldBandwidth = 0
01472     );
01474 
01486     virtual PBoolean GetAdmissionRequestAuthentication(
01487       H323GatekeeperARQ & info,           
01488       H235Authenticators & authenticators 
01489     );
01490 
01496     virtual PBoolean GetUsersPassword(
01497       const PString & alias,
01498       PString & password,
01499       H323RegisteredEndPoint & registeredEndpoint
01500     ) const;
01501     virtual PBoolean GetUsersPassword(
01502       const PString & alias,
01503       PString & password
01504     ) const;
01506 
01507 #if OPAL_H501
01508 
01512     H323PeerElement * GetPeerElement() const { return peerElement; }
01513 
01517     void SetPeerElement(
01518       H323PeerElement * newPeerElement
01519     );
01520 
01526     void CreatePeerElement(
01527       const H323TransportAddress & h501Interface
01528     );
01529 
01535     PBoolean OpenPeerElement(
01536       const H323TransportAddress & remotePeer,
01537       PBoolean append = PFalse,
01538       PBoolean keepTrying = PTrue
01539     );
01541 #endif
01542 
01547     const PString & GetGatekeeperIdentifier() const { return gatekeeperIdentifier; }
01548 
01554     void SetGatekeeperIdentifier(
01555       const PString & id,
01556       PBoolean adjustListeners = PTrue
01557     );
01558 
01561     unsigned GetAvailableBandwidth() const { return totalBandwidth; }
01562 
01565     void SetAvailableBandwidth(unsigned bps100) { totalBandwidth = bps100; }
01566 
01569     unsigned GetUsedBandwidth() const { return usedBandwidth; }
01570 
01573     unsigned GetDefaultBandwidth() const { return defaultBandwidth; }
01574 
01577     unsigned GetTimeToLive() const { return defaultTimeToLive; }
01578 
01581     void SetTimeToLive(unsigned seconds) { defaultTimeToLive = seconds; }
01582 
01585     unsigned GetInfoResponseRate() const { return defaultInfoResponseRate; }
01586 
01589     void SetInfoResponseRate(unsigned seconds) { defaultInfoResponseRate = seconds; }
01590 
01593     PBoolean IsGatekeeperRouted() const { return isGatekeeperRouted; }
01594 
01597     PBoolean IsRequiredH235() const { return requireH235; }
01598 
01601     unsigned GetActiveRegistrations() const { return byIdentifier.GetSize(); }
01602 
01605     unsigned GetPeakRegistrations() const { return peakRegistrations; }
01606 
01609     unsigned GetTotalRegistrations() const { return totalRegistrations; }
01610 
01613     unsigned GetRejectedRegistrations() const { return rejectedRegistrations; }
01614 
01617     unsigned GetActiveCalls() const { return activeCalls.GetSize(); }
01618 
01621     unsigned GetPeakCalls() const { return peakCalls; }
01622 
01625     unsigned GetTotalCalls() const { return totalCalls; }
01626 
01629     unsigned GetRejectedCalls() const { return rejectedCalls; }
01631 
01632     
01633     void RemoveAlias(
01634       H323RegisteredEndPoint & ep,
01635       const PString & alias
01636     );
01637 
01638     
01639     virtual PBoolean OnSendDescriptorForEndpoint(
01640       H323RegisteredEndPoint & ,                    
01641       H225_ArrayOf_AliasAddress & ,            
01642       H225_EndpointType & ,               
01643       H225_ArrayOf_AliasAddress &   
01644     )
01645     { return PTrue; } 
01646 
01647     virtual PBoolean AllowDuplicateAlias(const H225_ArrayOf_AliasAddress & )
01648     { return canHaveDuplicateAlias; }
01649 
01650     virtual PBoolean OnSendFeatureSet(unsigned, H225_FeatureSet & features) const;
01651     virtual void OnReceiveFeatureSet(unsigned, const H225_FeatureSet & features) const;
01652 
01653   protected:
01654 
01655     PDECLARE_NOTIFIER(PThread, H323GatekeeperServer, MonitorMain);
01656 
01657     
01658     PString  gatekeeperIdentifier;
01659     unsigned totalBandwidth;
01660     unsigned usedBandwidth;
01661     unsigned defaultBandwidth;
01662     unsigned maximumBandwidth;
01663     unsigned defaultTimeToLive;
01664     unsigned defaultInfoResponseRate;
01665     PBoolean     overwriteOnSameSignalAddress;
01666     PBoolean     canHaveDuplicateAlias;
01667     PBoolean     canHaveDuplicatePrefix;
01668     PBoolean     canOnlyCallRegisteredEP;
01669     PBoolean     canOnlyAnswerRegisteredEP;
01670     PBoolean     answerCallPreGrantedARQ;
01671     PBoolean     makeCallPreGrantedARQ;
01672     PBoolean     isGatekeeperRouted;
01673     PBoolean     aliasCanBeHostName;
01674     PBoolean     requireH235;
01675     PBoolean     disengageOnHearbeatFail;
01676 
01677     PStringToString passwords;
01678 
01679     
01680     PMutex         mutex;
01681     time_t         identifierBase;
01682     unsigned       nextIdentifier;
01683     PThread      * monitorThread;
01684     PSyncPoint     monitorExit;
01685 
01686     PLIST(ListenerList, H323GatekeeperListener);
01687     ListenerList listeners;
01688 
01689 #if OPAL_H501
01690     H323PeerElement * peerElement;
01691 #endif
01692 
01693     PSafeDictionary<PString, H323RegisteredEndPoint> byIdentifier;
01694 
01695     class StringMap : public PString {
01696         PCLASSINFO(StringMap, PString);
01697       public:
01698         StringMap(const PString & from, const PString & id)
01699           : PString(from), identifier(id) { }
01700         PString identifier;
01701     };
01702     PSortedStringList byAddress;
01703     PSortedStringList byAlias;
01704     PSortedStringList byVoicePrefix;
01705 
01706     PSafeSortedList<H323GatekeeperCall> activeCalls;
01707 
01708     PINDEX peakRegistrations;
01709     PINDEX totalRegistrations;
01710     PINDEX rejectedRegistrations;
01711     PINDEX peakCalls;
01712     PINDEX totalCalls;
01713     PINDEX rejectedCalls;
01714 
01715   friend class H323GatekeeperRRQ;
01716   friend class H323GatekeeperARQ;
01717 };
01718 
01719 
01720 #endif // OPAL_H323
01721 
01722 #endif // OPAL_H323_GKSERVER_H
01723 
01724 
01726