# gkclient.h

Go to the documentation of this file.

    00001 /*
    00002  * gkclient.h
    00003  *
    00004  * Gatekeeper client 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  * Portions of this code were written with the assisance of funding from
    00025  * iFace, Inc. http://www.iface.com
    00026  *
    00027  * Contributor(s): ______________________________________.
    00028  *
    00029  * $Revision: 21004 $
    00030  * $Author: rjongbloed $
    00031  * $Date: 2008-09-16 07:08:56 +0000 (Tue, 16 Sep 2008) $
    00032  */
    00033
    00034 #ifndef __OPAL_GKCLIENT_H
    00035 #define __OPAL_GKCLIENT_H
    00036
    00037 #ifdef P_USE_PRAGMA
    00038 #pragma interface
    00039 #endif
    00040
    00041 #include <opal/buildopts.h>
    00042
    00043 #include <h323/h225ras.h>
    00044 #include <h323/h235auth.h>
    00045
    00046 #if OPAL_H460
    00047 class H460_FeatureSet;
    00048 #endif
    00049
    00050 class H323Connection;
    00051 class H225_ArrayOf_AliasAddress;
    00052 class H225_H323_UU_PDU;
    00053 class H225_AlternateGK;
    00054 class H225_ArrayOf_AlternateGK;
    00055 class H225_ArrayOf_ServiceControlSession;
    00056 class H225_FeatureSet;
    00057
    00058
    00060
    00063 class H323Gatekeeper : public H225_RAS
    00064 {
    00065     PCLASSINFO(H323Gatekeeper, H225_RAS);
    00066   public:
    00071     H323Gatekeeper(
    00072       H323EndPoint & endpoint,
    00073       H323Transport * transport
    00074     );
    00075
    00078     ~H323Gatekeeper();
    00080
    00083     virtual PBoolean WriteTo(
    00084       H323TransactionPDU & pdu,
    00085       const H323TransportAddressArray & addresses,
    00086       PBoolean callback = PTrue
    00087     );
    00089
    00092     PBoolean OnReceiveGatekeeperConfirm(const H225_GatekeeperConfirm & gcf);
    00093     PBoolean OnReceiveGatekeeperReject(const H225_GatekeeperReject & grj);
    00094     PBoolean OnReceiveRegistrationConfirm(const H225_RegistrationConfirm & rcf);
    00095     PBoolean OnReceiveRegistrationReject(const H225_RegistrationReject & rrj);
    00096     PBoolean OnReceiveUnregistrationRequest(const H225_UnregistrationRequest & urq);
    00097     PBoolean OnReceiveUnregistrationConfirm(const H225_UnregistrationConfirm & ucf);
    00098     PBoolean OnReceiveUnregistrationReject(const H225_UnregistrationReject & urj);
    00099     PBoolean OnReceiveAdmissionConfirm(const H225_AdmissionConfirm & acf);
    00100     PBoolean OnReceiveAdmissionReject(const H225_AdmissionReject & arj);
    00101     PBoolean OnReceiveDisengageRequest(const H225_DisengageRequest & drq);
    00102     PBoolean OnReceiveBandwidthConfirm(const H225_BandwidthConfirm & bcf);
    00103     PBoolean OnReceiveBandwidthRequest(const H225_BandwidthRequest & brq);
    00104     PBoolean OnReceiveInfoRequest(const H225_InfoRequest & irq);
    00105     PBoolean OnReceiveServiceControlIndication(const H225_ServiceControlIndication &);
    00106     void OnSendGatekeeperRequest(H225_GatekeeperRequest & grq);
    00107     void OnSendAdmissionRequest(H225_AdmissionRequest & arq);
    00108     PBoolean OnSendFeatureSet(unsigned, H225_FeatureSet & features) const;
    00109     void OnReceiveFeatureSet(unsigned, const H225_FeatureSet & features) const;
    00111
    00116     PBoolean DiscoverAny();
    00117
    00122     PBoolean DiscoverByName(
    00123       const PString & identifier
    00124     );
    00125
    00130     PBoolean DiscoverByAddress(
    00131       const H323TransportAddress & address
    00132     );
    00133
    00137     PBoolean DiscoverByNameAndAddress(
    00138       const PString & identifier,
    00139       const H323TransportAddress & address
    00140     );
    00141
    00144     PBoolean RegistrationRequest(
    00145       PBoolean autoReregister = PTrue,
    00146       PBoolean didGkDiscovery = PFalse
    00147     );
    00148
    00151     PBoolean UnregistrationRequest(
    00152       int reason
    00153     );
    00154
    00157     PBoolean LocationRequest(
    00158       const PString & alias,
    00159       H323TransportAddress & address
    00160     );
    00161
    00164     PBoolean LocationRequest(
    00165       const PStringList & aliases,
    00166       H323TransportAddress & address
    00167     );
    00168
    00169     struct AdmissionResponse {
    00170       AdmissionResponse();
    00171
    00172       unsigned rejectReason;
    00173
    00174       PBoolean gatekeeperRouted;
    00175       PINDEX endpointCount;
    00176       H323TransportAddress * transportAddress;
    00177       PBYTEArray * accessTokenData;
    00178
    00179       H225_ArrayOf_AliasAddress * aliasAddresses;
    00180       H225_ArrayOf_AliasAddress * destExtraCallInfo;
    00181     };
    00182
    00185     PBoolean AdmissionRequest(
    00186       H323Connection & connection,
    00187       AdmissionResponse & response,
    00188       PBoolean ignorePreGrantedARQ = PFalse
    00189     );
    00190
    00193     PBoolean DisengageRequest(
    00194       const H323Connection & connection,
    00195       unsigned reason
    00196     );
    00197
    00200     PBoolean BandwidthRequest(
    00201       H323Connection & connection,
    00202       unsigned requestedBandwidth
    00203     );
    00204
    00207     void InfoRequestResponse();
    00208
    00211     void InfoRequestResponse(
    00212       const H323Connection & connection
    00213     );
    00214
    00217     void InfoRequestResponse(
    00218       const H323Connection & connection,
    00219       const H225_H323_UU_PDU & pdu,
    00220       PBoolean sent
    00221     );
    00222
    00225     virtual void OnServiceControlSessions(
    00226       const H225_ArrayOf_ServiceControlSession & serviceControl,
    00227       H323Connection * connection
    00228     );
    00229
    00232     virtual void OnTerminalAliasChanged();
    00234
    00239     PBoolean IsDiscoveryComplete() const { return discoveryComplete; }
    00240
    00243     PBoolean IsRegistered() const { return registrationFailReason == RegistrationSuccessful; }
    00244
    00245     enum RegistrationFailReasons {
    00246       RegistrationSuccessful,
    00247       UnregisteredLocally,
    00248       UnregisteredByGatekeeper,
    00249       GatekeeperLostRegistration,
    00250       InvalidListener,
    00251       DuplicateAlias,
    00252       SecurityDenied,
    00253       TransportError,
    00254       NumRegistrationFailReasons,
    00255       RegistrationRejectReasonMask = 0x8000
    00256     };
    00259     RegistrationFailReasons GetRegistrationFailReason() const { return registrationFailReason; }
    00260
    00269     PString GetName() const;
    00270
    00273     const PString & GetEndpointIdentifier() const { return endpointIdentifier; }
    00274
    00279     void SetPassword(
    00280       const PString & password,
    00281       const PString & username = PString()
    00282     );
    00283
    00284     /*
    00285      * Return the call signalling address for the gatekeeper (if present)
    00286      */
    00287     H323TransportAddress GetGatekeeperRouteAddress() const
    00288     { return gkRouteAddress; }
    00290
    00291
    00292   protected:
    00293     bool StartGatekeeper(const H323TransportAddress & address);
    00294     virtual bool DiscoverGatekeeper();
    00295     unsigned SetupGatekeeperRequest(H323RasPDU & request);
    00296
    00297     void Connect(const H323TransportAddress & address, const PString & gatekeeperIdentifier);
    00298     PDECLARE_NOTIFIER(PThread, H323Gatekeeper, MonitorMain);
    00299     PDECLARE_NOTIFIER(PTimer, H323Gatekeeper, TickleMonitor);
    00300     void RegistrationTimeToLive();
    00301
    00302     void SetInfoRequestRate(
    00303       const PTimeInterval & rate
    00304     );
    00305     void ClearInfoRequestRate();
    00306     H225_InfoRequestResponse & BuildInfoRequestResponse(
    00307       H323RasPDU & response,
    00308       unsigned seqNum
    00309     );
    00310     PBoolean SendUnsolicitedIRR(
    00311       H225_InfoRequestResponse & irr,
    00312       H323RasPDU & response
    00313     );
    00314
    00315     void SetAlternates(
    00316       const H225_ArrayOf_AlternateGK & alts,
    00317       PBoolean permanent
    00318     );
    00319
    00320     virtual PBoolean MakeRequest(
    00321       Request & request
    00322     );
    00323     PBoolean MakeRequestWithReregister(
    00324       Request & request,
    00325       unsigned unregisteredTag
    00326     );
    00327
    00328     virtual H323Transport * CreateTransport(PIPSocket::Address bindng = PIPSocket::GetDefaultIpAny(), WORD port = 0, PBoolean reuseAddr = PFalse);
    00329
    00330     // Handling interface changes
    00331     void OnAddInterface(const PIPSocket::InterfaceEntry & entry, PINDEX priority);
    00332     void OnRemoveInterface(const PIPSocket::InterfaceEntry & entry, PINDEX priority);
    00333     void UpdateConnectionStatus();
    00334
    00335
    00336     // Gatekeeper registration state variables
    00337     PBoolean     discoveryComplete;
    00338     PString  endpointIdentifier;
    00339     RegistrationFailReasons registrationFailReason;
    00340
    00341     enum {
    00342       HighPriority = 80,
    00343       LowPriority  = 40,
    00344     };
    00345     class InterfaceMonitor : public PInterfaceMonitorClient
    00346     {
    00347       PCLASSINFO(InterfaceMonitor, PInterfaceMonitorClient);
    00348
    00349       public:
    00350         InterfaceMonitor(H323Gatekeeper & gk, PINDEX priority);
    00351
    00352       protected:
    00353         virtual void OnAddInterface(const PIPSocket::InterfaceEntry & entry);
    00354         virtual void OnRemoveInterface(const PIPSocket::InterfaceEntry & entry);
    00355
    00356         H323Gatekeeper & gk;
    00357     };
    00358     InterfaceMonitor highPriorityMonitor;
    00359     InterfaceMonitor lowPriorityMonitor;
    00360
    00361     class AlternateInfo : public PObject {
    00362       PCLASSINFO(AlternateInfo, PObject);
    00363       public:
    00364         AlternateInfo(H225_AlternateGK & alt);
    00365         ~AlternateInfo();
    00366         Comparison Compare(const PObject & obj);
    00367         void PrintOn(ostream & strm) const;
    00368
    00369         H323TransportAddress rasAddress;
    00370         PString              gatekeeperIdentifier;
    00371         unsigned             priority;
    00372         enum {
    00373           NoRegistrationNeeded,
    00374           NeedToRegister,
    00375           Register,
    00376           IsRegistered,
    00377           RegistrationFailed
    00378         } registrationState;
    00379
    00380       private:
    00381         // Disable copy constructor and assignment
    00382         AlternateInfo(const AlternateInfo &other): PObject(other) { }
    00383         AlternateInfo & operator=(const AlternateInfo &) { return *this; }
    00384     };
    00385     PSortedList<AlternateInfo> alternates;
    00386     PBoolean               alternatePermanent;
    00387     PSemaphore         requestMutex;
    00388     H235Authenticators authenticators;
    00389
    00390     enum {
    00391       RequireARQ,
    00392       PregrantARQ,
    00393       PreGkRoutedARQ
    00394     } pregrantMakeCall, pregrantAnswerCall;
    00395     H323TransportAddress gkRouteAddress;
    00396
    00397     // Gatekeeper operation variables
    00398     PBoolean       autoReregister;
    00399     PBoolean       reregisterNow;
    00400     PTimer     timeToLive;
    00401     PBoolean       requiresDiscovery;
    00402     PTimer     infoRequestRate;
    00403     PBoolean       willRespondToIRR;
    00404     PThread  * monitor;
    00405     PBoolean       monitorStop;
    00406     PSyncPoint monitorTickle;
    00407
    00408     PDictionary<POrdinalKey, H323ServiceControlSession> serviceControlSessions;
    00409
    00410 #if OPAL_H460
    00411     H460_FeatureSet * features;
    00412 #endif
    00413
    00414 };
    00415
    00416
    00417 PLIST(H323GatekeeperList, H323Gatekeeper);
    00418
    00419
    00420 #endif // __OPAL_GKCLIENT_H
    00421
    00422