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 * $Revision: 28283 $ 00029 * $Author: rjongbloed $ 00030 * $Date: 2012-08-30 21:08:15 -0500 (Thu, 30 Aug 2012) $ 00031 */ 00032 00033 #ifndef OPAL_IAX2_REMOTE_H 00034 #define OPAL_IAX2_REMOTE_H 00035 00036 #ifndef _PTLIB_H 00037 #include <ptlib.h> 00038 #endif 00039 00040 #include <opal/buildopts.h> 00041 00042 #if OPAL_IAX2 00043 00044 #include <ptlib/sockets.h> 00045 #include <ptclib/pssl.h> 00046 00047 #ifdef P_USE_PRAGMA 00048 #pragma interface 00049 #endif 00050 00051 class IAX2FullFrame; 00052 00053 00056 class IAX2Remote : public PObject 00057 { 00058 PCLASSINFO(IAX2Remote, PObject); 00059 00060 public: 00061 00063 IAX2Remote(); 00064 00065 virtual ~IAX2Remote() { }; 00066 00069 PINDEX DestCallNumber() { return destCallNumber; } 00070 00074 PINDEX SourceCallNumber() { return sourceCallNumber; } 00075 00077 virtual void PrintOn(ostream & strm) const; 00078 00080 enum { 00081 callNumberUndefined = 0xffff 00082 }; 00083 00085 PIPSocket::Address RemoteAddress() { return remoteAddress; } 00086 00090 PString BuildConnectionToken(); 00091 00093 PString BuildOurConnectionToken(); 00094 00096 PINDEX RemotePort() { return remotePort; } 00097 00099 void Assign(IAX2Remote &); 00100 00102 void SetRemoteAddress(PIPSocket::Address &newVal) { remoteAddress = newVal; } 00103 00105 void SetRemoteAddress(int newVal) { remoteAddress = newVal; } 00106 00108 void SetRemotePort (PINDEX newVal) { remotePort = newVal; } 00109 00111 void SetSourceCallNumber(PINDEX newVal) { sourceCallNumber = newVal; } 00112 00114 void SetDestCallNumber(PINDEX newVal); 00115 00119 PBoolean operator == (IAX2Remote & other); 00120 00123 PBoolean operator *= (IAX2Remote & other); 00124 00125 00127 PBoolean operator != (IAX2Remote & other); 00128 00129 00130 protected: 00132 PINDEX sourceCallNumber; 00133 00135 PINDEX destCallNumber; 00136 00138 PIPSocket::Address remoteAddress; 00139 00141 PINDEX remotePort; 00142 00143 }; 00144 00146 00155 class IAX2FrameIdValue : public PObject 00156 { 00157 PCLASSINFO(IAX2FrameIdValue, PObject); 00158 public: 00160 IAX2FrameIdValue (PINDEX timeStamp, PINDEX seqVal); 00161 00163 IAX2FrameIdValue (PINDEX val); 00164 00166 PINDEX GetTimeStamp() const; 00167 00169 PINDEX GetSequenceVal() const; 00170 00174 PINDEX GetPlainSequence() const; 00175 00177 virtual void PrintOn(ostream & strm) const; 00178 00181 virtual Comparison Compare(const PObject & obj) const; 00182 00183 protected: 00184 00187 PUInt64 value; 00188 }; 00189 00191 00196 PDECLARE_SORTED_LIST(IAX2PacketIdList, IAX2FrameIdValue) 00197 #ifdef DOC_PLUS_PLUS 00198 class IAX2PacketIdList : public PSortedList 00199 { 00200 #endif 00201 00204 PBoolean Contains(IAX2FrameIdValue &src); 00205 00208 PINDEX GetFirstValue(); 00209 00211 void AppendNewFrame(IAX2FullFrame &src); 00212 00214 virtual void PrintOn(ostream & strm) const; 00215 00216 protected: 00222 void RemoveOldContiguousValues(); 00223 }; 00224 00226 00227 class IAX2SequenceNumbers 00228 { 00229 public: 00233 enum IncomingOrder { 00234 InSequence, 00235 SkippedFrame, 00236 RepeatedFrame 00237 }; 00238 00239 00240 00242 IAX2SequenceNumbers() 00243 { ZeroAllValues(); }; 00244 00246 virtual ~IAX2SequenceNumbers() { } 00247 00249 void ZeroAllValues(); 00250 00252 PINDEX InSeqNo(); 00253 00255 PINDEX OutSeqNo(); 00256 00259 PBoolean IsFirstReplyFrame(); 00260 00263 PBoolean IsSequenceNosZero(); 00264 00266 void SetInSeqNo(PINDEX newVal); 00267 00269 void SetOutSeqNo(PINDEX newVal); 00270 00273 void SetInOutSeqNo(PINDEX inVal, PINDEX outVal); 00274 00277 void SetAckSequenceInfo(IAX2SequenceNumbers & other); 00278 00280 PBoolean operator !=(IAX2SequenceNumbers &other); 00281 00283 PBoolean operator ==(IAX2SequenceNumbers &other); 00284 00286 void MassageSequenceForSending(IAX2FullFrame &src /*<!src will be transmitted to the remote node */ 00287 ); 00288 00292 void WrapAroundFrameSequence(IAX2SequenceNumbers & src); 00293 00297 IncomingOrder IncomingMessageInOrder 00298 (IAX2FullFrame &src /*<!frame to be compared with current data base.*/ ); 00299 00301 void CopyContents(IAX2SequenceNumbers &src); 00302 00304 PString AsString() const; 00305 00307 virtual void PrintOn(ostream & strm) const; 00308 00311 PBoolean IsFirstReply() { return (inSeqNo == 1) && (outSeqNo == 0); } 00312 00314 void AddWrapAroundValue(PINDEX newOffset); 00315 00316 00317 protected: 00318 00320 enum sequenceDefines { 00321 minSpacing = 3 00322 }; 00323 00325 PINDEX inSeqNo; 00326 00328 PINDEX outSeqNo; 00329 00331 PMutex mutex; 00332 00334 PINDEX lastSentTimeStamp; 00335 00337 IAX2PacketIdList receivedLog; 00338 }; 00339 00341 00342 class IAX2Encryption : public PObject 00343 { 00344 PCLASSINFO(IAX2Encryption, PObject); 00345 public: 00347 IAX2Encryption(); 00348 00350 void SetEncryptionOn (PBoolean newState = true); 00351 00353 void SetEncryptionKey(PString & newKey); 00354 00356 void SetChallengeKey(PString & newKey); 00357 00359 const PString & EncryptionKey() const; 00360 00362 const PString & ChallengeKey() const; 00363 00365 PBoolean IsEncrypted() const; 00366 00367 #ifdef P_SSL_AES 00368 00369 PAESContext & AesEncryptKey() { return m_aesEncryptKey; } 00370 00372 PAESContext & AesDecryptKey() { return m_aesDecryptKey; } 00373 #endif 00374 00375 protected: 00378 void CalculateAesKeys(); 00379 00381 PString encryptionKey; 00382 00384 PString challengeKey; 00385 00387 PBoolean encryptionEnabled; 00388 00389 #ifdef P_SSL_AES 00390 00391 PAESContext m_aesEncryptKey; 00392 00394 PAESContext m_aesDecryptKey; 00395 #endif 00396 }; 00397 00399 00400 00401 #endif // OPAL_IAX2 00402 00403 #endif // OPAL_IAX2_REMOTE_H 00404 00405 /* The comment below is magic for those who use emacs to edit this file. 00406 * With the comment below, the tab key does auto indent to 2 spaces. 00407 * 00408 * Local Variables: 00409 * mode:c 00410 * c-basic-offset:2 00411 * End: 00412 */