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 
00348   virtual OpalMediaFormatList GetMediaFormats() const;
00349 
00350   virtual PBoolean OnIncomingCall(IAX2Connection & conn);
00351 
00353   PINDEX GetSupportedCodecs(OpalMediaFormatList & list);
00354   
00356   PINDEX GetPreferredCodec(OpalMediaFormatList & list);
00357 
00360   void GetCodecLengths(PINDEX src, PINDEX &compressedBytes, PINDEX &duration);
00361   
00367   enum IAX2RemoteAddressFields {
00368     protoIndex     = 0,     
00369     userIndex      = 1,     
00370     transportIndex = 2,     
00371     addressIndex   = 3,     
00372     extensionIndex = 4,     
00373     contextIndex   = 5,     
00374     maximumIndex   = 6      
00375   };
00376 
00383   static PStringArray DissectRemoteParty(const PString & other);
00384 
00388   void ProcessReceivedEthernetFrames();
00389 
00390 
00393   void ReportTransmitterLists();
00394 
00396   void CopyLocalMediaFormats(OpalMediaFormatList & list);
00397   
00403   void Register(
00404       const PString & host,
00405       const PString & username,
00406       const PString & password = PString::Empty(),
00407       PINDEX requestedRefreshTime = 60
00408     );
00409   
00410   enum RegisteredError {
00411     RegisteredFailureUnknown
00412   };
00413   
00416   virtual void OnRegistered(
00417       const PString & host,
00418       const PString & userName,
00419       PBoolean isFailure,
00420       RegisteredError reason = RegisteredFailureUnknown);
00421    
00424   void Unregister(
00425       const PString & host,
00426       const PString & username);
00427       
00428   enum UnregisteredError {
00429     UnregisteredFailureUnknown
00430   };
00431       
00436   virtual void OnUnregistered(
00437       const PString & host,
00438       const PString & userName,
00439       PBoolean isFailure,
00440       UnregisteredError reason = UnregisteredFailureUnknown);
00441       
00442   
00444   PBoolean IsRegistered(const PString & host, const PString & username);
00445   
00447   PINDEX GetRegistrationsCount();
00448   
00450   PString BuildUrl(
00451     const PString & host,
00452     const PString & userName = PString::Empty(),
00453     const PString & extension = PString::Empty(),
00454     const PString & context = PString::Empty(),
00455     const PString & transport = PString::Empty()
00456   );
00457   
00459   
00460  protected:
00467   IAX2IncomingEthernetFrames incomingFrameHandler;
00468 
00471   IAX2FrameList   packetsReadFromEthernet;
00472   
00474   PUDPSocket  *sock;
00475   
00477   int callnumbs;
00478   
00480   PMutex callNumbLock;
00481   
00483   PTime callStartTime;
00484   
00486   PString localUserName;
00487   
00489   PString localNumber;
00490   
00492   PString password;
00493   
00495   PINDEX statusQueryCounter;
00496   
00498   PMutex statusQueryMutex;
00499   
00502   IAX2SpecialProcessor * specialPacketHandler;
00503     
00511   PBoolean ProcessInMatchingConnection(IAX2Frame *f);  
00512     
00520   PBoolean AddNewTranslationEntry(IAX2Frame *f);
00521   
00534   PStringToString    tokenTable;
00535   
00537   PMutex             mutexTokenTable;
00538 
00541   PAtomicInteger callsEstablished;
00542 
00544   OpalMediaFormatList localMediaFormats;
00545   
00547   PMutex regProcessorsMutex;
00548   
00553   PArrayObjects regProcessors;
00554   
00555 };
00556 
00557 #endif // IAX_ENDPOINT_H
00558 /* The comment below is magic for those who use emacs to edit this file. */
00559 /* With the comment below, the tab key does auto indent to 4 spaces.     */
00560 
00561 /*
00562  * Local Variables:
00563  * mode:c
00564  * c-file-style:linux
00565  * c-basic-offset:2
00566  * End:
00567  */
00568 

Generated on Fri Mar 7 07:36:35 2008 for OPAL by  doxygen 1.5.1