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/endpoint.h>
00115 #include <iax2/iax2con.h>
00116 #include <iax2/processor.h>
00117 #include <iax2/regprocessor.h>
00118 #include <iax2/specialprocessor.h>
00119 
00120 class IAX2Receiver;
00121 class IAX2Transmit;
00122 class IAX2Processor;
00123 
00127 class IAX2IncomingEthernetFrames : public PThread
00128 {
00129   PCLASSINFO(IAX2IncomingEthernetFrames, PThread);
00130 public:
00131 
00135   IAX2IncomingEthernetFrames();
00136    
00138   ~IAX2IncomingEthernetFrames() { }
00139 
00142   /*The method which gets everythig to happen */
00143   virtual void Main();
00144    
00146   void Assign(IAX2EndPoint *ep);
00147 
00150   void ProcessList();
00151 
00153   void Terminate();
00154 
00156  protected:
00158   IAX2EndPoint *endpoint;
00159    
00161   PSyncPoint activate;
00162 
00164   PBoolean           keepGoing;
00165 };
00166 
00167 
00168 
00169 
00171 class IAX2EndPoint : public OpalEndPoint
00172 {
00173   PCLASSINFO(IAX2EndPoint, OpalEndPoint);
00174  public:
00179   IAX2EndPoint(
00180     OpalManager & manager
00181   );
00182   
00184   ~IAX2EndPoint();
00186   
00193   virtual PBoolean NewIncomingConnection(
00194     OpalTransport * transport  
00195   );
00196   
00226   virtual PBoolean MakeConnection(
00227                               OpalCall & call,          
00228                               const PString & party,    
00229                               void * userData = NULL,   
00230                               unsigned int options = 0, 
00231                               OpalConnection::StringOptions * stringOptions = NULL
00232                               );
00233   
00237   virtual IAX2Connection * CreateConnection(
00238                                            OpalCall & call,            
00239                                            const PString & token,      
00240                                            void * userData,             
00241                                            const PString & remoteParty, 
00242              const PString & remotePartyName = PString::Empty() 
00243                                            );
00245   
00250   PBoolean Initialise();
00251 
00253   virtual void IncomingEthernetFrame (IAX2Frame *frame);
00254   
00260   PBoolean ConectionForFrameIsAlive(IAX2Frame *f);
00261   
00268   PINDEX NextSrcCallNumber(IAX2Processor * processor);
00269       
00272   void ReportStoredConnections();
00273   
00275   WORD ListenPortNumber()  { return 4569; }
00276       
00278   IAX2Transmit *transmitter;
00279   
00281   IAX2Receiver    *receiver;
00282   
00284   PString GetLocalUserName() { return localUserName; }
00285   
00287   PString GetLocalNumber() { return localNumber; }
00288   
00290   void SetLocalUserName(PString newValue); 
00291   
00293   void SetLocalNumber(PString newValue);
00294   
00296   PString & GetPassword() { return password; }
00297   
00299   void SetPassword(PString newValue);
00300 
00307   PBoolean ConnectionForFrameIsAlive(IAX2Frame *f);
00308  
00310   PINDEX GetOutSequenceNumberForStatusQuery();
00311   
00313   void StartRinging(PString remoteCaller);
00314   
00326     void NewIncomingConnection(
00327       IAX2Frame *f  
00328                 );
00329 
00335     void OnEstablished(
00336        OpalConnection & con
00337     );
00338 
00344     virtual void OnReleased(
00345       OpalConnection & connection   
00346     );
00347 
00357   virtual OpalMediaFormatList GetMediaFormats() const;
00358 
00359   virtual PBoolean OnIncomingCall(IAX2Connection & conn);
00360 
00362   PINDEX GetSupportedCodecs(OpalMediaFormatList & list);
00363   
00365   PINDEX GetPreferredCodec(OpalMediaFormatList & list);
00366 
00369   void GetCodecLengths(PINDEX src, PINDEX &compressedBytes, PINDEX &duration);
00370   
00376   enum IAX2RemoteAddressFields {
00377     protoIndex     = 0,     
00378     userIndex      = 1,     
00379     transportIndex = 2,     
00380     addressIndex   = 3,     
00381     extensionIndex = 4,     
00382     contextIndex   = 5,     
00383     maximumIndex   = 6      
00384   };
00385 
00392   static PStringArray DissectRemoteParty(const PString & other);
00393 
00397   void ProcessReceivedEthernetFrames();
00398 
00401   void ReportTransmitterLists(PString & answer, bool getFullReport = false);
00402 
00404   void CopyLocalMediaFormats(OpalMediaFormatList & list);
00405   
00411   void Register(
00412       const PString & host,
00413       const PString & username,
00414       const PString & password = PString::Empty(),
00415       PINDEX requestedRefreshTime = 60
00416     );
00417   
00418   enum RegisteredError {
00419     RegisteredFailureUnknown
00420   };
00421   
00424   virtual void OnRegistered(
00425       const PString & host,
00426       const PString & userName,
00427       PBoolean isFailure,
00428       RegisteredError reason = RegisteredFailureUnknown);
00429    
00432   void Unregister(
00433       const PString & host,
00434       const PString & username);
00435       
00436   enum UnregisteredError {
00437     UnregisteredFailureUnknown
00438   };
00439       
00444   virtual void OnUnregistered(
00445       const PString & host,
00446       const PString & userName,
00447       PBoolean isFailure,
00448       UnregisteredError reason = UnregisteredFailureUnknown);
00449       
00450   
00452   PBoolean IsRegistered(const PString & host, const PString & username);
00453   
00455   PINDEX GetRegistrationsCount();
00456   
00458   PString BuildUrl(
00459     const PString & host,
00460     const PString & userName = PString::Empty(),
00461     const PString & extension = PString::Empty(),
00462     const PString & context = PString::Empty(),
00463     const PString & transport = PString::Empty()
00464   );
00465   
00467   
00468  protected:
00475   IAX2IncomingEthernetFrames incomingFrameHandler;
00476 
00479   IAX2FrameList   packetsReadFromEthernet;
00480   
00482   PUDPSocket  *sock;
00483   
00485   int callnumbs;
00486   
00488   PMutex callNumbLock;
00489   
00491   PTime callStartTime;
00492   
00494   PString localUserName;
00495   
00497   PString localNumber;
00498   
00500   PString password;
00501   
00503   PINDEX statusQueryCounter;
00504   
00506   PMutex statusQueryMutex;
00507   
00510   IAX2SpecialProcessor * specialPacketHandler;
00511     
00519   PBoolean ProcessInMatchingConnection(IAX2Frame *f);  
00520     
00528   PBoolean AddNewTranslationEntry(IAX2Frame *f);
00529   
00542   PStringToString    tokenTable;
00543   
00547   PReadWriteMutex    mutexTokenTable;
00548 
00551   PAtomicInteger callsEstablished;
00552 
00554   OpalMediaFormatList localMediaFormats;
00555   
00557   PMutex regProcessorsMutex;
00558   
00563   PArrayObjects regProcessors;
00564   
00565 };
00566 
00567 #endif // IAX_ENDPOINT_H
00568 /* The comment below is magic for those who use emacs to edit this file. */
00569 /* With the comment below, the tab key does auto indent to 2 spaces.     */
00570 
00571 /*
00572  * Local Variables:
00573  * mode:c
00574  * c-basic-offset:2
00575  * End:
00576  */
00577 

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