# iax2ep.h

Go to the documentation of this file.

    00001 /*
    00002  *
    00003  * Inter Asterisk Exchange 2
    00004  *
    00005  * Open Phone Abstraction Library (OPAL)
    00006  *
    00007  * Describes the IAX2 extension of the OpalEndpoint class.
    00008  *
    00009  * Copyright (c) 2005 Indranet Technologies Ltd.
    00010  *
    00011  * The contents of this file are subject to the Mozilla Public License
    00012  * Version 1.0 (the "License"); you may not use this file except in
    00013  * compliance with the License. You may obtain a copy of the License at
    00014  * http://www.mozilla.org/MPL/
    00015  *
    00016  * Software distributed under the License is distributed on an "AS IS"
    00017  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
    00018  * the License for the specific language governing rights and limitations
    00019  * under the License.
    00020  *
    00021  * The Original Code is Open Phone Abstraction Library.
    00022  *
    00023  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
    00024  *
    00025  * The author of this code is Derek J Smithies
    00026  *
    00027  *  $Log: iax2ep.h,v $
    00028  *  Revision 1.17  2007/08/13 04:24:26  csoutheren
    00029  *  Normalise IAX2 answer logic
    00030  *
    00031  *  Revision 1.16  2007/08/09 22:15:44  dereksmithies
    00032  *  Formatting tidyup. No functional difference.
    00033  *
    00034  *  Revision 1.15  2007/08/03 01:24:06  dereksmithies
    00035  *  Tidyups so it compiles...
    00036  *
    00037  *  Revision 1.14  2007/08/02 23:25:07  dereksmithies
    00038  *  Rework iax2 handling of incoming calls. This should ensure that woomera/simpleopal etc
    00039  *  will correctly advise on receiving an incoming call.
    00040  *
    00041  *  Revision 1.13  2007/04/19 06:17:21  csoutheren
    00042  *  Fixes for precompiled headers with gcc
    00043  *
    00044  *  Revision 1.12  2007/03/13 00:32:16  csoutheren
    00045  *  Simple but messy changes to allow compile time removal of protocol
    00046  *  options such as H.450 and H.460
    00047  *  Fix MakeConnection overrides
    00048  *
    00049  *  Revision 1.11  2007/03/01 05:51:03  rjongbloed
    00050  *  Fixed backward compatibility of OnIncomingConnection() virtual
    00051  *    functions on various classes. If an old override returned PFalse
    00052  *    then it will now abort the call as it used to.
    00053  *
    00054  *  Revision 1.10  2007/01/24 04:00:55  csoutheren
    00055  *  Arrrghh. Changing OnIncomingConnection turned out to have a lot of side-effects
    00056  *  Added some pure viritual functions to prevent old code from breaking silently
    00057  *  New OpalEndpoint and OpalConnection descendants will need to re-implement
    00058  *  OnIncomingConnection. Sorry :)
    00059  *
    00060  *  Revision 1.9  2007/01/12 02:39:00  dereksmithies
    00061  *  Remove the notion of srcProcessors and dstProcessor lists from the ep.
    00062  *  Ensure that the connection looks after the callProcessor.
    00063  *
    00064  *  Revision 1.8  2007/01/09 03:32:23  dereksmithies
    00065  *  Tidy up and improve the close down process - make it more robust.
    00066  *  Alter level of several PTRACE statements. Add Terminate() method to transmitter and receiver.
    00067  *
    00068  *  Revision 1.7  2006/12/18 03:18:41  csoutheren
    00069  *  Messy but simple fixes
    00070  *    - Add access to SIP REGISTER timeout
    00071  *    - Ensure OpalConnection options are correctly progagated
    00072  *
    00073  *  Revision 1.6  2006/09/11 03:08:51  dereksmithies
    00074  *  Add fixes from Stephen Cook (sitiveni@gmail.com) for new patches to
    00075  *  improve call handling. Notably, IAX2 call transfer. Many thanks.
    00076  *  Thanks also to the Google summer of code for sponsoring this work.
    00077  *
    00078  *  Revision 1.5  2006/08/09 03:46:39  dereksmithies
    00079  *  Add ability to register to a remote Asterisk box. The iaxProcessor class is split
    00080  *  into a callProcessor and a regProcessor class.
    00081  *  Big thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
    00082  *
    00083  *  Revision 1.4  2005/08/26 03:07:38  dereksmithies
    00084  *  Change naming convention, so all class names contain the string "IAX2"
    00085  *
    00086  *  Revision 1.3  2005/08/24 01:38:38  dereksmithies
    00087  *  Add encryption, iax2 style. Numerous tidy ups. Use the label iax2, not iax
    00088  *
    00089  *  Revision 1.2  2005/08/04 08:14:17  rjongbloed
    00090  *  Fixed Windows build under DevStudio 2003 of IAX2 code
    00091  *
    00092  *  Revision 1.1  2005/07/30 07:01:32  csoutheren
    00093  *  Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol
    00094  *  Thanks to Derek Smithies of Indranet Technologies Ltd. for
    00095  *  writing and contributing this code
    00096  *
    00097  *
    00098  *
    00099  *
    00100  *
    00101  */
    00102
    00103 #ifndef IAX_ENDPOINT_H
    00104 #define IAX_ENDPOINT_H
    00105
    00106 #ifndef _PTLIB_H
    00107 #include <ptlib.h>
    00108 #endif
    00109
    00110 #ifdef P_USE_PRAGMA
    00111 #pragma interface
    00112 #endif
    00113
    00114 #include <opal/buildopts.h>
    00115
    00116 #include <opal/endpoint.h>
    00117 #include <iax2/iax2con.h>
    00118 #include <iax2/processor.h>
    00119 #include <iax2/regprocessor.h>
    00120 #include <iax2/specialprocessor.h>
    00121
    00122 class IAX2Receiver;
    00123 class IAX2Transmit;
    00124 class IAX2Processor;
    00125
    00129 class IAX2IncomingEthernetFrames : public PThread
    00130 {
    00131   PCLASSINFO(IAX2IncomingEthernetFrames, PThread);
    00132 public:
    00133
    00137   IAX2IncomingEthernetFrames();
    00138
    00140   ~IAX2IncomingEthernetFrames() { }
    00141
    00144   /*The method which gets everythig to happen */
    00145   virtual void Main();
    00146
    00148   void Assign(IAX2EndPoint *ep);
    00149
    00152   void ProcessList();
    00153
    00155   void Terminate();
    00156
    00158  protected:
    00160   IAX2EndPoint *endpoint;
    00161
    00163   PSyncPoint activate;
    00164
    00166   PBoolean           keepGoing;
    00167 };
    00168
    00169
    00170
    00171
    00173 class IAX2EndPoint : public OpalEndPoint
    00174 {
    00175   PCLASSINFO(IAX2EndPoint, OpalEndPoint);
    00176  public:
    00181   IAX2EndPoint(
    00182     OpalManager & manager
    00183   );
    00184
    00186   ~IAX2EndPoint();
    00188
    00195   virtual PBoolean NewIncomingConnection(
    00196     OpalTransport * transport
    00197   );
    00198
    00228   virtual PBoolean MakeConnection(
    00229                               OpalCall & call,
    00230                               const PString & party,
    00231                               void * userData = NULL,
    00232                               unsigned int options = 0,
    00233                               OpalConnection::StringOptions * stringOptions = NULL
    00234                               );
    00235
    00239   virtual IAX2Connection * CreateConnection(
    00240                                            OpalCall & call,
    00241                                            const PString & token,
    00242                                            void * userData,
    00243                                            const PString & remoteParty,
    00244              const PString & remotePartyName = PString::Empty()
    00245                                            );
    00247
    00252   PBoolean Initialise();
    00253
    00255   virtual void IncomingEthernetFrame (IAX2Frame *frame);
    00256
    00262   PBoolean ConectionForFrameIsAlive(IAX2Frame *f);
    00263
    00270   PINDEX NextSrcCallNumber(IAX2Processor * processor);
    00271
    00274   void ReportStoredConnections();
    00275
    00277   WORD ListenPortNumber()  { return 4569; }
    00278
    00280   IAX2Transmit *transmitter;
    00281
    00283   IAX2Receiver    *receiver;
    00284
    00286   PString GetLocalUserName() { return localUserName; }
    00287
    00289   PString GetLocalNumber() { return localNumber; }
    00290
    00292   void SetLocalUserName(PString newValue);
    00293
    00295   void SetLocalNumber(PString newValue);
    00296
    00298   PString & GetPassword() { return password; }
    00299
    00301   void SetPassword(PString newValue);
    00302
    00309   PBoolean ConnectionForFrameIsAlive(IAX2Frame *f);
    00310
    00312   PINDEX GetOutSequenceNumberForStatusQuery();
    00313
    00315   void StartRinging(PString remoteCaller);
    00316
    00328     void NewIncomingConnection(
    00329       IAX2Frame *f
    00330                 );
    00331
    00337     void OnEstablished(
    00338        OpalConnection & con
    00339     );
    00340
    00346     virtual void OnReleased(
    00347       OpalConnection & connection
    00348     );
    00349
    00359   virtual OpalMediaFormatList GetMediaFormats() const;
    00360
    00361   virtual PBoolean OnIncomingCall(IAX2Connection & conn);
    00362
    00364   PINDEX GetSupportedCodecs(OpalMediaFormatList & list);
    00365
    00367   PINDEX GetPreferredCodec(OpalMediaFormatList & list);
    00368
    00371   void GetCodecLengths(PINDEX src, PINDEX &compressedBytes, PINDEX &duration);
    00372
    00378   enum IAX2RemoteAddressFields {
    00379     protoIndex     = 0,
    00380     userIndex      = 1,
    00381     transportIndex = 2,
    00382     addressIndex   = 3,
    00383     extensionIndex = 4,
    00384     contextIndex   = 5,
    00385     maximumIndex   = 6
    00386   };
    00387
    00394   static PStringArray DissectRemoteParty(const PString & other);
    00395
    00399   void ProcessReceivedEthernetFrames();
    00400
    00403   void ReportTransmitterLists(PString & answer, bool getFullReport = false);
    00404
    00406   void CopyLocalMediaFormats(OpalMediaFormatList & list);
    00407
    00413   void Register(
    00414       const PString & host,
    00415       const PString & username,
    00416       const PString & password = PString::Empty(),
    00417       PINDEX requestedRefreshTime = 60
    00418     );
    00419
    00420   enum RegisteredError {
    00421     RegisteredFailureUnknown
    00422   };
    00423
    00426   virtual void OnRegistered(
    00427       const PString & host,
    00428       const PString & userName,
    00429       PBoolean isFailure,
    00430       RegisteredError reason = RegisteredFailureUnknown);
    00431
    00434   void Unregister(
    00435       const PString & host,
    00436       const PString & username);
    00437
    00438   enum UnregisteredError {
    00439     UnregisteredFailureUnknown
    00440   };
    00441
    00446   virtual void OnUnregistered(
    00447       const PString & host,
    00448       const PString & userName,
    00449       PBoolean isFailure,
    00450       UnregisteredError reason = UnregisteredFailureUnknown);
    00451
    00452
    00454   PBoolean IsRegistered(const PString & host, const PString & username);
    00455
    00457   PINDEX GetRegistrationsCount();
    00458
    00460   PString BuildUrl(
    00461     const PString & host,
    00462     const PString & userName = PString::Empty(),
    00463     const PString & extension = PString::Empty(),
    00464     const PString & context = PString::Empty(),
    00465     const PString & transport = PString::Empty()
    00466   );
    00467
    00469
    00470  protected:
    00477   IAX2IncomingEthernetFrames incomingFrameHandler;
    00478
    00481   IAX2FrameList   packetsReadFromEthernet;
    00482
    00484   PUDPSocket  *sock;
    00485
    00487   int callnumbs;
    00488
    00490   PMutex callNumbLock;
    00491
    00493   PTime callStartTime;
    00494
    00496   PString localUserName;
    00497
    00499   PString localNumber;
    00500
    00502   PString password;
    00503
    00505   PINDEX statusQueryCounter;
    00506
    00508   PMutex statusQueryMutex;
    00509
    00512   IAX2SpecialProcessor * specialPacketHandler;
    00513
    00521   PBoolean ProcessInMatchingConnection(IAX2Frame *f);
    00522
    00530   PBoolean AddNewTranslationEntry(IAX2Frame *f);
    00531
    00544   PStringToString    tokenTable;
    00545
    00549   PReadWriteMutex    mutexTokenTable;
    00550
    00553   PAtomicInteger callsEstablished;
    00554
    00556   OpalMediaFormatList localMediaFormats;
    00557
    00559   PMutex regProcessorsMutex;
    00560
    00565   PArrayObjects regProcessors;
    00566
    00567 };
    00568
    00569 #endif // IAX_ENDPOINT_H
    00570 /* The comment below is magic for those who use emacs to edit this file. */
    00571 /* With the comment below, the tab key does auto indent to 2 spaces.     */
    00572
    00573 /*
    00574  * Local Variables:
    00575  * mode:c
    00576  * c-basic-offset:2
    00577  * End:
    00578  */
    00579