remote.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Inter Asterisk Exchange 2
00005  * 
00006  * A class to describe the node we are talking to.
00007  * 
00008  * Open Phone Abstraction Library (OPAL)
00009  *
00010  * Copyright (c) 2005 Indranet Technologies Ltd.
00011  *
00012  * The contents of this file are subject to the Mozilla Public License
00013  * Version 1.0 (the "License"); you may not use this file except in
00014  * compliance with the License. You may obtain a copy of the License at
00015  * http://www.mozilla.org/MPL/
00016  *
00017  * Software distributed under the License is distributed on an "AS IS"
00018  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00019  * the License for the specific language governing rights and limitations
00020  * under the License.
00021  *
00022  * The Original Code is Open Phone Abstraction Library.
00023  *
00024  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
00025  *
00026  * The author of this code is Derek J Smithies
00027  *
00028  *  $Log: remote.h,v $
00029  *  Revision 1.8  2007/04/19 06:17:21  csoutheren
00030  *  Fixes for precompiled headers with gcc
00031  *
00032  *  Revision 1.7  2007/01/23 02:08:25  dereksmithies
00033  *  Handle Vnak frames correctly. handle iseqno and oseqno correctly.
00034  *
00035  *  Revision 1.6  2006/08/09 03:46:40  dereksmithies
00036  *  Add ability to register to a remote Asterisk box. The iaxProcessor class is split
00037  *  into a callProcessor and a regProcessor class.
00038  *  Big thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
00039  *
00040  *  Revision 1.5  2005/08/28 23:51:29  dereksmithies
00041  *  Improve test for massaging timestamps in fullframes. Thanks to Adrian Sietsma
00042  *
00043  *  Revision 1.4  2005/08/26 03:07:38  dereksmithies
00044  *  Change naming convention, so all class names contain the string "IAX2"
00045  *
00046  *  Revision 1.3  2005/08/24 13:06:18  rjongbloed
00047  *  Added configuration define for AEC encryption
00048  *
00049  *  Revision 1.2  2005/08/24 01:38:38  dereksmithies
00050  *  Add encryption, iax2 style. Numerous tidy ups. Use the label iax2, not iax
00051  *
00052  *  Revision 1.1  2005/07/30 07:01:32  csoutheren
00053  *  Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol
00054  *  Thanks to Derek Smithies of Indranet Technologies Ltd. for
00055  *  writing and contributing this code
00056  *
00057  *
00058  *
00059  *
00060  */
00061 
00062 #ifndef REMOTE_H
00063 #define REMOTE_H
00064 
00065 #ifndef _PTLIB_H
00066 #include <ptlib.h>
00067 #endif
00068 
00069 #include <ptlib/sockets.h>
00070 
00071 #if P_SSL_AES
00072 #include <openssl/aes.h>
00073 #endif
00074 
00075 #ifdef P_USE_PRAGMA
00076 #pragma interface
00077 #endif
00078 
00079 class IAX2FullFrame;
00080 
00081 
00084 class IAX2Remote : public PObject
00085 { 
00086   PCLASSINFO(IAX2Remote, PObject);
00087   
00088  public:
00089   
00091   IAX2Remote();
00092   
00093   virtual ~IAX2Remote() { };
00094   
00097   PINDEX DestCallNumber() { return destCallNumber; }
00098   
00102   PINDEX SourceCallNumber() { return sourceCallNumber; }
00103  
00105   virtual void PrintOn(ostream & strm) const; 
00106   
00108   enum {
00109     callNumberUndefined = 0xffff 
00110   };
00111   
00113   PIPSocket::Address RemoteAddress() { return remoteAddress; }
00114   
00118   PString BuildConnectionTokenId();
00119 
00121   PString BuildOurConnectionTokenId();
00122 
00124   PINDEX   RemotePort() { return remotePort; }
00125   
00127   void Assign(IAX2Remote &);
00128   
00130   void SetRemoteAddress(PIPSocket::Address &newVal) { remoteAddress = newVal; }
00131   
00133   void SetRemoteAddress(int newVal) { remoteAddress = newVal; }
00134   
00136   void SetRemotePort (PINDEX newVal) { remotePort = newVal; }
00137   
00139   void SetSourceCallNumber(PINDEX newVal) { sourceCallNumber = newVal; }
00140   
00142   void SetDestCallNumber(PINDEX newVal) { destCallNumber = newVal; }
00143   
00147   PBoolean operator == (IAX2Remote & other);
00148   
00151   PBoolean operator *= (IAX2Remote & other);
00152   
00153   
00155   PBoolean operator != (IAX2Remote & other);
00156   
00157   
00158  protected:
00160   PINDEX       sourceCallNumber;    
00161   
00163   PINDEX       destCallNumber;      
00164   
00166   PIPSocket::Address remoteAddress; 
00167   
00169   PINDEX               remotePort;    
00170 
00171 };
00172 
00174 
00183 class IAX2FrameIdValue : public PObject
00184 {
00185   PCLASSINFO(IAX2FrameIdValue, PObject);
00186  public:
00188   IAX2FrameIdValue (PINDEX timeStamp, PINDEX seqVal);
00189 
00191   IAX2FrameIdValue (PINDEX val);
00192 
00194   PINDEX GetTimeStamp() const;
00195 
00197   PINDEX GetSequenceVal() const;
00198 
00202   PINDEX GetPlainSequence() const;
00203 
00205   virtual void PrintOn(ostream & strm) const;
00206 
00209   virtual Comparison Compare(const PObject & obj) const;
00210 
00211  protected:
00212 
00215   PUInt64 value;
00216 };
00217 
00219 
00224 PDECLARE_SORTED_LIST(IAX2PacketIdList, IAX2FrameIdValue)
00225 #ifdef DOC_PLUS_PLUS
00226 class IAX2PacketIdList : public PSortedList
00227 {
00228 #endif
00229   
00232   PBoolean Contains(IAX2FrameIdValue &src);
00233   
00236   PINDEX GetFirstValue();
00237   
00239   void AppendNewFrame(IAX2FullFrame &src);
00240   
00242   virtual void PrintOn(ostream & strm) const;   
00243   
00244  protected:
00250   void RemoveOldContiguousValues();
00251 };
00252 
00254 
00255 class IAX2SequenceNumbers
00256 {
00257  public:
00261   enum IncomingOrder {
00262     InSequence,  
00263     SkippedFrame, 
00264     RepeatedFrame 
00265   };
00266 
00267 
00268 
00270   IAX2SequenceNumbers() 
00271     { ZeroAllValues();   };
00272   
00274   virtual ~IAX2SequenceNumbers() { }
00275   
00277   void ZeroAllValues();
00278   
00280   PINDEX InSeqNo();
00281   
00283   PINDEX OutSeqNo();
00284   
00287   PBoolean IsSequenceNosZero();
00288 
00290   void SetInSeqNo(PINDEX newVal);
00291   
00293   void SetOutSeqNo(PINDEX newVal);
00294 
00297   void SetInOutSeqNo(PINDEX inVal, PINDEX outVal);
00298   
00301   void SetAckSequenceInfo(IAX2SequenceNumbers & other);
00302   
00304   PBoolean  operator !=(IAX2SequenceNumbers &other);
00305   
00307   PBoolean operator ==(IAX2SequenceNumbers &other);
00308   
00310   void MassageSequenceForSending(IAX2FullFrame &src /*<!src will be transmitted to the remote node */
00311                                  );
00312 
00316   void WrapAroundFrameSequence(IAX2SequenceNumbers & src);
00317   
00321   IncomingOrder IncomingMessageInOrder
00322     (IAX2FullFrame &src /*<!frame to be compared with current data base.*/  );
00323   
00325   void CopyContents(IAX2SequenceNumbers &src);
00326   
00328   PString AsString() const;
00329   
00331   virtual void PrintOn(ostream & strm) const;
00332 
00335   PBoolean IsFirstReply() { return (inSeqNo == 1) && (outSeqNo == 0); }
00336 
00338   void AddWrapAroundValue(PINDEX newOffset);
00339 
00340 
00341  protected:
00342 
00344   enum sequenceDefines {
00345     minSpacing = 3   
00346   };
00347   
00349   PINDEX inSeqNo;  
00350   
00352   PINDEX outSeqNo; 
00353 
00355   PMutex mutex;
00356 
00358   PINDEX lastSentTimeStamp;
00359 
00361   IAX2PacketIdList receivedLog;
00362 };
00363 
00365 
00366 class IAX2Encryption : public PObject 
00367 {
00368   PCLASSINFO(IAX2Encryption, PObject);
00369  public:
00371   IAX2Encryption();
00372 
00374   void SetEncryptionOn (PBoolean newState = PTrue);
00375 
00377   void SetEncryptionKey(PString & newKey);
00378 
00380   void SetChallengeKey(PString & newKey);
00381 
00383   const PString & EncryptionKey() const;
00384 
00386   const PString & ChallengeKey() const;
00387 
00389   const PBoolean IsEncrypted() const;
00390 
00391 #if P_SSL_AES
00392 
00393   AES_KEY *AesEncryptKey();
00394 
00396   AES_KEY *AesDecryptKey();
00397 #endif
00398 
00399  protected:
00402   void CalculateAesKeys();
00403 
00405   PString encryptionKey;
00406 
00408   PString challengeKey;
00409 
00411   PBoolean encryptionEnabled;
00412 
00413 #if P_SSL_AES
00414 
00415   AES_KEY aesEncryptKey;
00416 
00418   AES_KEY aesDecryptKey;
00419 #endif
00420 };
00421 
00423 
00424 #endif
00425 
00426 /* The comment below is magic for those who use emacs to edit this file. */
00427 /* With the comment below, the tab key does auto indent to 4 spaces.     */
00428 
00429 /*
00430  * Local Variables:
00431  * mode:c
00432  * c-basic-offset:2
00433  * End:
00434  */
00435 

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