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 FALSE
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   BOOL           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 BOOL NewIncomingConnection(
00194     OpalTransport * transport  
00195   );
00196   
00226   virtual BOOL 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   BOOL Initialise();
00251 
00253   virtual void IncomingEthernetFrame (IAX2Frame *frame);
00254   
00260   BOOL 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   BOOL ConnectionForFrameIsAlive(IAX2Frame *f);
00308  
00310   PINDEX GetOutSequenceNumberForStatusQuery();
00311   
00313   void StartRinging(PString remoteCaller);
00314   
00326     void NewIncomingConnection(
00327       IAX2Frame *f  
00328                 );
00329 
00332     void OnEstablished(
00333        OpalConnection & con
00334     );
00335 
00345   virtual OpalMediaFormatList GetMediaFormats() const;
00346 
00347   virtual BOOL OnIncomingCall(IAX2Connection & conn);
00348 
00350   PINDEX GetSupportedCodecs(OpalMediaFormatList & list);
00351   
00353   PINDEX GetPreferredCodec(OpalMediaFormatList & list);
00354 
00357   void GetCodecLengths(PINDEX src, PINDEX &compressedBytes, PINDEX &duration);
00358   
00364   enum IAX2RemoteAddressFields {
00365     protoIndex     = 0,     
00366     userIndex      = 1,     
00367     transportIndex = 2,     
00368     addressIndex   = 3,     
00369     extensionIndex = 4,     
00370     contextIndex   = 5,     
00371     maximumIndex   = 6      
00372   };
00373 
00380   static PStringList DissectRemoteParty(const PString & other);
00381 
00385   void ProcessReceivedEthernetFrames();
00386 
00387 
00390   void ReportTransmitterLists();
00391 
00393   void CopyLocalMediaFormats(OpalMediaFormatList & list);
00394   
00400   void Register(
00401       const PString & host,
00402       const PString & username,
00403       const PString & password = PString::Empty(),
00404       PINDEX requestedRefreshTime = 60
00405     );
00406   
00407   enum RegisteredError {
00408     RegisteredFailureUnknown
00409   };
00410   
00413   virtual void OnRegistered(
00414       const PString & host,
00415       const PString & userName,
00416       BOOL isFailure,
00417       RegisteredError reason = RegisteredFailureUnknown);
00418    
00421   void Unregister(
00422       const PString & host,
00423       const PString & username);
00424       
00425   enum UnregisteredError {
00426     UnregisteredFailureUnknown
00427   };
00428       
00433   virtual void OnUnregistered(
00434       const PString & host,
00435       const PString & userName,
00436       BOOL isFailure,
00437       UnregisteredError reason = UnregisteredFailureUnknown);
00438       
00439   
00441   BOOL IsRegistered(const PString & host, const PString & username);
00442   
00444   PINDEX GetRegistrationsCount();
00445   
00447   PString BuildUrl(
00448     const PString & host,
00449     const PString & userName = PString::Empty(),
00450     const PString & extension = PString::Empty(),
00451     const PString & context = PString::Empty(),
00452     const PString & transport = PString::Empty()
00453   );
00454   
00456   
00457  protected:
00464   IAX2IncomingEthernetFrames incomingFrameHandler;
00465 
00468   IAX2FrameList   packetsReadFromEthernet;
00469   
00471   PUDPSocket  *sock;
00472   
00474   int callnumbs;
00475   
00477   PMutex callNumbLock;
00478   
00480   PTime callStartTime;
00481   
00483   PString localUserName;
00484   
00486   PString localNumber;
00487   
00489   PString password;
00490   
00492   PINDEX statusQueryCounter;
00493   
00495   PMutex statusQueryMutex;
00496   
00499   IAX2SpecialProcessor * specialPacketHandler;
00500     
00508   BOOL ProcessInMatchingConnection(IAX2Frame *f);  
00509     
00517   BOOL AddNewTranslationEntry(IAX2Frame *f);
00518   
00531   PStringToString    tokenTable;
00532   
00534   PMutex             mutexTokenTable;
00535 
00538   PAtomicInteger callsEstablished;
00539 
00541   OpalMediaFormatList localMediaFormats;
00542   
00544   PMutex regProcessorsMutex;
00545   
00550   PArrayObjects regProcessors;
00551   
00552 };
00553 
00554 #endif // IAX_ENDPOINT_H
00555 /* The comment below is magic for those who use emacs to edit this file. */
00556 /* With the comment below, the tab key does auto indent to 4 spaces.     */
00557 
00558 /*
00559  * Local Variables:
00560  * mode:c
00561  * c-file-style:linux
00562  * c-basic-offset:2
00563  * End:
00564  */
00565 

Generated on Fri Mar 7 06:33:37 2008 for OPAL by  doxygen 1.5.1