00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00046 #if OPAL_PTLIB_SSL_AES
00047 #include <openssl/aes.h>
00048 #endif
00049
00050 #ifdef P_USE_PRAGMA
00051 #pragma interface
00052 #endif
00053
00054 class IAX2FullFrame;
00055
00056
00059 class IAX2Remote : public PObject
00060 {
00061 PCLASSINFO(IAX2Remote, PObject);
00062
00063 public:
00064
00066 IAX2Remote();
00067
00068 virtual ~IAX2Remote() { };
00069
00072 PINDEX DestCallNumber() { return destCallNumber; }
00073
00077 PINDEX SourceCallNumber() { return sourceCallNumber; }
00078
00080 virtual void PrintOn(ostream & strm) const;
00081
00083 enum {
00084 callNumberUndefined = 0xffff
00085 };
00086
00088 PIPSocket::Address RemoteAddress() { return remoteAddress; }
00089
00093 PString BuildConnectionTokenId();
00094
00096 PString BuildOurConnectionTokenId();
00097
00099 PINDEX RemotePort() { return remotePort; }
00100
00102 void Assign(IAX2Remote &);
00103
00105 void SetRemoteAddress(PIPSocket::Address &newVal) { remoteAddress = newVal; }
00106
00108 void SetRemoteAddress(int newVal) { remoteAddress = newVal; }
00109
00111 void SetRemotePort (PINDEX newVal) { remotePort = newVal; }
00112
00114 void SetSourceCallNumber(PINDEX newVal) { sourceCallNumber = newVal; }
00115
00117 void SetDestCallNumber(PINDEX newVal) { destCallNumber = newVal; }
00118
00122 PBoolean operator == (IAX2Remote & other);
00123
00126 PBoolean operator *= (IAX2Remote & other);
00127
00128
00130 PBoolean operator != (IAX2Remote & other);
00131
00132
00133 protected:
00135 PINDEX sourceCallNumber;
00136
00138 PINDEX destCallNumber;
00139
00141 PIPSocket::Address remoteAddress;
00142
00144 PINDEX remotePort;
00145
00146 };
00147
00149
00158 class IAX2FrameIdValue : public PObject
00159 {
00160 PCLASSINFO(IAX2FrameIdValue, PObject);
00161 public:
00163 IAX2FrameIdValue (PINDEX timeStamp, PINDEX seqVal);
00164
00166 IAX2FrameIdValue (PINDEX val);
00167
00169 PINDEX GetTimeStamp() const;
00170
00172 PINDEX GetSequenceVal() const;
00173
00177 PINDEX GetPlainSequence() const;
00178
00180 virtual void PrintOn(ostream & strm) const;
00181
00184 virtual Comparison Compare(const PObject & obj) const;
00185
00186 protected:
00187
00190 PUInt64 value;
00191 };
00192
00194
00199 PDECLARE_SORTED_LIST(IAX2PacketIdList, IAX2FrameIdValue)
00200 #ifdef DOC_PLUS_PLUS
00201 class IAX2PacketIdList : public PSortedList
00202 {
00203 #endif
00204
00207 PBoolean Contains(IAX2FrameIdValue &src);
00208
00211 PINDEX GetFirstValue();
00212
00214 void AppendNewFrame(IAX2FullFrame &src);
00215
00217 virtual void PrintOn(ostream & strm) const;
00218
00219 protected:
00225 void RemoveOldContiguousValues();
00226 };
00227
00229
00230 class IAX2SequenceNumbers
00231 {
00232 public:
00236 enum IncomingOrder {
00237 InSequence,
00238 SkippedFrame,
00239 RepeatedFrame
00240 };
00241
00242
00243
00245 IAX2SequenceNumbers()
00246 { ZeroAllValues(); };
00247
00249 virtual ~IAX2SequenceNumbers() { }
00250
00252 void ZeroAllValues();
00253
00255 PINDEX InSeqNo();
00256
00258 PINDEX OutSeqNo();
00259
00262 PBoolean IsSequenceNosZero();
00263
00265 void SetInSeqNo(PINDEX newVal);
00266
00268 void SetOutSeqNo(PINDEX newVal);
00269
00272 void SetInOutSeqNo(PINDEX inVal, PINDEX outVal);
00273
00276 void SetAckSequenceInfo(IAX2SequenceNumbers & other);
00277
00279 PBoolean operator !=(IAX2SequenceNumbers &other);
00280
00282 PBoolean operator ==(IAX2SequenceNumbers &other);
00283
00285 void MassageSequenceForSending(IAX2FullFrame &src
00286 );
00287
00291 void WrapAroundFrameSequence(IAX2SequenceNumbers & src);
00292
00296 IncomingOrder IncomingMessageInOrder
00297 (IAX2FullFrame &src );
00298
00300 void CopyContents(IAX2SequenceNumbers &src);
00301
00303 PString AsString() const;
00304
00306 virtual void PrintOn(ostream & strm) const;
00307
00310 PBoolean IsFirstReply() { return (inSeqNo == 1) && (outSeqNo == 0); }
00311
00313 void AddWrapAroundValue(PINDEX newOffset);
00314
00315
00316 protected:
00317
00319 enum sequenceDefines {
00320 minSpacing = 3
00321 };
00322
00324 PINDEX inSeqNo;
00325
00327 PINDEX outSeqNo;
00328
00330 PMutex mutex;
00331
00333 PINDEX lastSentTimeStamp;
00334
00336 IAX2PacketIdList receivedLog;
00337 };
00338
00340
00341 class IAX2Encryption : public PObject
00342 {
00343 PCLASSINFO(IAX2Encryption, PObject);
00344 public:
00346 IAX2Encryption();
00347
00349 void SetEncryptionOn (PBoolean newState = PTrue);
00350
00352 void SetEncryptionKey(PString & newKey);
00353
00355 void SetChallengeKey(PString & newKey);
00356
00358 const PString & EncryptionKey() const;
00359
00361 const PString & ChallengeKey() const;
00362
00364 PBoolean IsEncrypted() const;
00365
00366 #if OPAL_PTLIB_SSL_AES
00367
00368 AES_KEY *AesEncryptKey();
00369
00371 AES_KEY *AesDecryptKey();
00372 #endif
00373
00374 protected:
00377 void CalculateAesKeys();
00378
00380 PString encryptionKey;
00381
00383 PString challengeKey;
00384
00386 PBoolean encryptionEnabled;
00387
00388 #if OPAL_PTLIB_SSL_AES
00389
00390 AES_KEY aesEncryptKey;
00391
00393 AES_KEY aesDecryptKey;
00394 #endif
00395 };
00396
00398
00399
00400 #endif // OPAL_IAX2
00401
00402 #endif // OPAL_IAX2_REMOTE_H
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412