# processor.h

Go to the documentation of this file.

    00001 /*
    00002  *
    00003  * Inter Asterisk Exchange 2
    00004  *
    00005  * The core routine which determines the processing of packets for one call.
    00006  *
    00007  * Open Phone Abstraction Library (OPAL)
    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  *
    00028  *  $Log: processor.h,v $
    00029  *  Revision 1.16  2007/04/19 06:17:21  csoutheren
    00030  *  Fixes for precompiled headers with gcc
    00031  *
    00032  *  Revision 1.15  2007/01/23 02:08:25  dereksmithies
    00033  *  Handle Vnak frames correctly. handle iseqno and oseqno correctly.
    00034  *
    00035  *  Revision 1.14  2007/01/17 03:48:13  dereksmithies
    00036  *  Tidy up comments, remove leaks, improve reporting of packet types.
    00037  *
    00038  *  Revision 1.13  2007/01/16 03:17:42  dereksmithies
    00039  *  tidyup of comments. Remove unused variables.
    00040  *  Guarantee that media frames are sent with a monotonically increasing timestamp
    00041  *
    00042  *  Revision 1.12  2007/01/11 03:02:15  dereksmithies
    00043  *  Remove the previous audio buffering code, and switch to using the jitter
    00044  *  buffer provided in Opal. Reduce the verbosity of the log mesasges.
    00045  *
    00046  *  Revision 1.11  2006/09/22 00:33:19  csoutheren
    00047  *  Changed PAtomicInteger to PBoolean
    00048  *
    00049  *  Revision 1.10  2006/09/11 03:08:51  dereksmithies
    00050  *  Add fixes from Stephen Cook (sitiveni@gmail.com) for new patches to
    00051  *  improve call handling. Notably, IAX2 call transfer. Many thanks.
    00052  *  Thanks also to the Google summer of code for sponsoring this work.
    00053  *
    00054  *  Revision 1.9  2006/08/09 03:46:39  dereksmithies
    00055  *  Add ability to register to a remote Asterisk box. The iaxProcessor class is split
    00056  *  into a callProcessor and a regProcessor class.
    00057  *  Big thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
    00058  *
    00059  *  Revision 1.8  2006/06/16 01:47:08  dereksmithies
    00060  *  Get the OnHold features of IAX2 to work correctly.
    00061  *  Thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
    00062  *
    00063  *  Revision 1.7  2005/09/05 01:19:43  dereksmithies
    00064  *  add patches from Adrian Sietsma to avoid multiple hangup packets at call end,
    00065  *  and stop the sending of ping/lagrq packets at call end. Many thanks.
    00066  *
    00067  *  Revision 1.6  2005/08/26 03:07:38  dereksmithies
    00068  *  Change naming convention, so all class names contain the string "IAX2"
    00069  *
    00070  *  Revision 1.5  2005/08/25 03:26:06  dereksmithies
    00071  *  Add patch from Adrian Sietsma to correctly set the packet timestamps under windows.
    00072  *  Many thanks.
    00073  *
    00074  *  Revision 1.4  2005/08/24 04:56:25  dereksmithies
    00075  *  Add code from Adrian Sietsma to send FullFrameTexts and FullFrameDtmfs to
    00076  *  the remote end.  Many Thanks.
    00077  *
    00078  *  Revision 1.3  2005/08/24 01:38:38  dereksmithies
    00079  *  Add encryption, iax2 style. Numerous tidy ups. Use the label iax2, not iax
    00080  *
    00081  *  Revision 1.2  2005/08/04 08:14:17  rjongbloed
    00082  *  Fixed Windows build under DevStudio 2003 of IAX2 code
    00083  *
    00084  *  Revision 1.1  2005/07/30 07:01:32  csoutheren
    00085  *  Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol
    00086  *  Thanks to Derek Smithies of Indranet Technologies Ltd. for
    00087  *  writing and contributing this code
    00088  *
    00089  *
    00090  *
    00091  *
    00092  *
    00093  *
    00094  *
    00095  */
    00096
    00097 #ifndef PROCESSOR_H
    00098 #define PROCESSOR_H
    00099
    00100 #ifndef _PTLIB_H
    00101 #include <ptlib.h>
    00102 #endif
    00103
    00104 #include <opal/buildopts.h>
    00105
    00106 #include <opal/connection.h>
    00107
    00108 #include <iax2/frame.h>
    00109 #include <iax2/iedata.h>
    00110 #include <iax2/remote.h>
    00111 #include <iax2/safestrings.h>
    00112 #include <iax2/sound.h>
    00113
    00114 class IAX2EndPoint;
    00115 class IAX2Connection;
    00116 class IAX2ThreadHelper;
    00117
    00119
    00140 class IAX2WaitingForAck : public PObject
    00141 {
    00142   PCLASSINFO(IAX2WaitingForAck, PObject);
    00143
    00144  public:
    00146   enum ResponseToAck {
    00147     RingingAcked   = 0,
    00148     AcceptAcked    = 1,
    00149     AuthRepAcked   = 2,
    00150     AnswerAcked    = 3
    00151   };
    00152
    00154   IAX2WaitingForAck();
    00155
    00157   void Assign(IAX2FullFrame *f, ResponseToAck _response);
    00158
    00160   PBoolean MatchingAckPacket(IAX2FullFrame *f);
    00161
    00163   ResponseToAck GetResponse() { return response; }
    00164
    00166   PString GetResponseAsString() const;
    00167
    00169   virtual void PrintOn(ostream & strm) const;
    00170
    00172   void ZeroValues();
    00173
    00174  private:
    00176   DWORD timeStamp;
    00177
    00179   PINDEX seqNo;
    00180
    00182   ResponseToAck response;
    00183 };
    00184
    00186
    00199 class IAX2Processor : public PThread
    00200 {
    00201   PCLASSINFO(IAX2Processor, PObject);
    00202
    00203  public:
    00205   IAX2Processor(IAX2EndPoint & ep);
    00206
    00208   virtual ~IAX2Processor();
    00209
    00211   IAX2SequenceNumbers & GetSequenceInfo() { return sequence; }
    00212
    00214   IAX2Encryption & GetEncryptionInfo() { return encryption; }
    00215
    00217   void IncomingEthernetFrame (IAX2Frame *frame);
    00218
    00221   virtual void PrintOn(ostream & strm) const = 0;
    00222
    00224   IAX2EndPoint & GetEndPoint() { return endpoint; };
    00225
    00235   void SetCallToken(const PString & newToken);
    00236
    00238   PString GetCallToken();
    00239
    00241   IAX2Remote & GetRemoteInfo() { return remote; }
    00242
    00244   const PTimeInterval & GetCallStartTick() { return callStartTick; }
    00245
    00249   void Main();
    00250
    00253   PBoolean IsStatusQueryEthernetFrame(IAX2Frame *frame);
    00254
    00257   void SetSpecialPackets(PBoolean newValue) { specialPackets = newValue; }
    00258
    00260   void Terminate();
    00261
    00266   void Activate();
    00267
    00274   virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff)= 0;
    00275
    00277   void ReportLists(PString & answer);
    00278
    00279  protected:
    00280
    00282   IAX2EndPoint      & endpoint;
    00283
    00287   PTimeInterval callStartTick;
    00288
    00290   IAX2Remote remote;
    00291
    00294   void StartNoResponseTimer(PINDEX msToWait = 60000);
    00295
    00297   void StopNoResponseTimer() { noResponseTimer.Stop(); }
    00298
    00300   PTimer noResponseTimer;
    00301
    00303   void CleanPendingLists() { activate.Signal(); }
    00304
    00307   IAX2WaitingForAck nextTask;
    00308
    00310   PSyncPoint activate;
    00311
    00313   PBoolean endThread;
    00314
    00316   IAX2Encryption encryption;
    00317
    00319   IAX2SequenceNumbers sequence;
    00320
    00322   IAX2ActiveFrameList frameList;
    00323
    00326   SafeString callToken;
    00327
    00329   virtual void OnNoResponseTimeout() = 0;
    00330
    00333   enum DefinedNoResponseTimePeriod {
    00334     NoResponseTimePeriod = 5000
    00335   };
    00336
    00340   PBoolean      IsHandlingSpecialPackets() { return specialPackets; };
    00341
    00344   PBoolean       specialPackets;
    00345
    00348   virtual void ProcessLists() = 0;
    00349
    00352   virtual void ProcessFullFrame(IAX2FullFrame & fullFrame) = 0;
    00353
    00356   virtual void ProcessIaxCmdLagRq(IAX2FullFrameProtocol *src);
    00357
    00360   virtual void ProcessIaxCmdLagRp(IAX2FullFrameProtocol *src);
    00361
    00364   virtual void ProcessIaxCmdVnak(IAX2FullFrameProtocol *src);
    00365
    00368   virtual void ProcessIaxCmdPing(IAX2FullFrameProtocol *src);
    00369
    00372   virtual void ProcessIaxCmdPong(IAX2FullFrameProtocol *src);
    00373
    00377   PBoolean ProcessOneIncomingEthernetFrame();
    00378
    00380   PAtomicInteger controlFramesSent;
    00381
    00383   PAtomicInteger controlFramesRcvd;
    00384
    00386   void IncControlFramesSent() { ++controlFramesSent; }
    00387
    00389   void IncControlFramesRcvd() { ++controlFramesRcvd; }
    00390
    00393   virtual void ProcessNetworkFrame(IAX2MiniFrame * src) = 0;
    00394
    00395   /* A frame of FullFrameProtocol type is labelled as AST_FRAME_IAX in the
    00396      asterisk souces, It will contain 0, 1, 2 or more Information Elements
    00397      (Ie) in the data section. This processor is used to do things that are
    00398      common to registration and call handling.
    00399
    00400   This method will eat/delete the supplied frame. Return PTrue on success,
    00401   PFalse on failure.*/
    00402   virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src);
    00403
    00407   void TransmitFrameToRemoteEndpoint(IAX2Frame *src);
    00408
    00414   void TransmitFrameToRemoteEndpoint(IAX2FullFrame *src,
    00415              IAX2WaitingForAck::ResponseToAck response
    00416              );
    00417
    00421   void TransmitFrameNow(IAX2Frame *src);
    00422
    00424   void TransmitFrameToRemoteEndpoint(IAX2FullFrameProtocol *src);
    00425
    00428   PBoolean Authenticate(IAX2FullFrameProtocol *reply,
    00429                     PString & password
    00430         );
    00431
    00433   IAX2IeData ieData;
    00434
    00437   void SendAckFrame(IAX2FullFrame *inReplyTo);
    00438
    00442   void SendVnakFrame(IAX2FullFrame *inReplyTo);
    00443
    00445   void SendUnsupportedFrame(IAX2FullFrame *inReplyTo);
    00446
    00447  private:
    00448 #ifdef DOC_PLUS_PLUS
    00449
    00456   void OnNoResponseTimeoutStart(PTimer &, INT);
    00457 #else
    00458   PDECLARE_NOTIFIER(PTimer, IAX2Processor, OnNoResponseTimeoutStart);
    00459 #endif
    00460
    00461  protected:
    00468   DWORD currentSoundTimeStamp;
    00469 };
    00470
    00471 #endif // PROCESSOR_H