OPAL  Version 3.14.3
remote.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Inter Asterisk Exchange 2
5  *
6  * A class to describe the node we are talking to.
7  *
8  * Open Phone Abstraction Library (OPAL)
9  *
10  * Copyright (c) 2005 Indranet Technologies Ltd.
11  *
12  * The contents of this file are subject to the Mozilla Public License
13  * Version 1.0 (the "License"); you may not use this file except in
14  * compliance with the License. You may obtain a copy of the License at
15  * http://www.mozilla.org/MPL/
16  *
17  * Software distributed under the License is distributed on an "AS IS"
18  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19  * the License for the specific language governing rights and limitations
20  * under the License.
21  *
22  * The Original Code is Open Phone Abstraction Library.
23  *
24  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
25  *
26  * The author of this code is Derek J Smithies
27  *
28  * $Revision: 29536 $
29  * $Author: rjongbloed $
30  * $Date: 2013-04-19 18:55:15 +1000 (Fri, 19 Apr 2013) $
31  */
32 
33 #ifndef OPAL_IAX2_REMOTE_H
34 #define OPAL_IAX2_REMOTE_H
35 
36 #ifndef _PTLIB_H
37 #include <ptlib.h>
38 #endif
39 
40 #include <opal_config.h>
41 
42 #if OPAL_IAX2
43 
44 #include <ptlib/sockets.h>
45 #include <ptclib/pssl.h>
46 
47 #ifdef P_USE_PRAGMA
48 #pragma interface
49 #endif
50 
51 class IAX2FullFrame;
52 
53 
56 class IAX2Remote : public PObject
57 {
58  PCLASSINFO(IAX2Remote, PObject);
59 
60  public:
61 
63  IAX2Remote();
64 
65  virtual ~IAX2Remote() { };
66 
69  PINDEX DestCallNumber() { return destCallNumber; }
70 
74  PINDEX SourceCallNumber() { return sourceCallNumber; }
75 
77  virtual void PrintOn(ostream & strm) const;
78 
80  enum {
82  };
83 
85  PIPSocket::Address RemoteAddress() { return remoteAddress; }
86 
90  PString BuildConnectionToken();
91 
93  PString BuildOurConnectionToken();
94 
96  PINDEX RemotePort() { return remotePort; }
97 
99  void Assign(IAX2Remote &);
100 
102  void SetRemoteAddress(PIPSocket::Address &newVal) { remoteAddress = newVal; }
103 
105  void SetRemoteAddress(int newVal) { remoteAddress = newVal; }
106 
108  void SetRemotePort (PINDEX newVal) { remotePort = newVal; }
109 
111  void SetSourceCallNumber(PINDEX newVal) { sourceCallNumber = newVal; }
112 
114  void SetDestCallNumber(PINDEX newVal);
115 
119  PBoolean operator == (IAX2Remote & other);
120 
123  PBoolean operator *= (IAX2Remote & other);
124 
125 
127  PBoolean operator != (IAX2Remote & other);
128 
129 
130  protected:
133 
135  PINDEX destCallNumber;
136 
138  PIPSocket::Address remoteAddress;
139 
141  PINDEX remotePort;
142 
143 };
144 
146 
155 class IAX2FrameIdValue : public PObject
156 {
157  PCLASSINFO(IAX2FrameIdValue, PObject);
158  public:
160  IAX2FrameIdValue (PINDEX timeStamp, PINDEX seqVal);
161 
163  IAX2FrameIdValue (PINDEX val);
164 
166  PINDEX GetTimeStamp() const;
167 
169  PINDEX GetSequenceVal() const;
170 
174  PINDEX GetPlainSequence() const;
175 
177  virtual void PrintOn(ostream & strm) const;
178 
181  virtual Comparison Compare(const PObject & obj) const;
182 
183  protected:
184 
187  PUInt64 value;
188 };
189 
191 
196 PDECLARE_SORTED_LIST(IAX2PacketIdList, IAX2FrameIdValue)
197 #ifdef DOC_PLUS_PLUS
198 class IAX2PacketIdList : public PSortedList
199 {
200 #endif
201 
204  PBoolean Contains(IAX2FrameIdValue &src);
205 
208  PINDEX GetFirstValue();
209 
211  void AppendNewFrame(IAX2FullFrame &src);
212 
214  virtual void PrintOn(ostream & strm) const;
215 
216  protected:
223 };
224 
226 
228 {
229  public:
237  };
238 
239 
240 
243  { ZeroAllValues(); };
244 
246  virtual ~IAX2SequenceNumbers() { }
247 
249  void ZeroAllValues();
250 
252  PINDEX InSeqNo();
253 
255  PINDEX OutSeqNo();
256 
259  PBoolean IsFirstReplyFrame();
260 
263  PBoolean IsSequenceNosZero();
264 
266  void SetInSeqNo(PINDEX newVal);
267 
269  void SetOutSeqNo(PINDEX newVal);
270 
273  void SetInOutSeqNo(PINDEX inVal, PINDEX outVal);
274 
278 
280  PBoolean operator !=(IAX2SequenceNumbers &other);
281 
283  PBoolean operator ==(IAX2SequenceNumbers &other);
284 
286  void MassageSequenceForSending(IAX2FullFrame &src /*<!src will be transmitted to the remote node */
287  );
288 
293 
298  (IAX2FullFrame &src /*<!frame to be compared with current data base.*/ );
299 
302 
304  PString AsString() const;
305 
307  virtual void PrintOn(ostream & strm) const;
308 
311  PBoolean IsFirstReply() { return (inSeqNo == 1) && (outSeqNo == 0); }
312 
314  void AddWrapAroundValue(PINDEX newOffset);
315 
316 
317  protected:
318 
322  };
323 
325  PINDEX inSeqNo;
326 
328  PINDEX outSeqNo;
329 
331  PMutex mutex;
332 
335 
338 };
339 
341 
342 class IAX2Encryption : public PObject
343 {
344  PCLASSINFO(IAX2Encryption, PObject);
345  public:
347  IAX2Encryption();
348 
350  void SetEncryptionOn (PBoolean newState = true);
351 
353  void SetEncryptionKey(PString & newKey);
354 
356  void SetChallengeKey(PString & newKey);
357 
359  const PString & EncryptionKey() const;
360 
362  const PString & ChallengeKey() const;
363 
365  PBoolean IsEncrypted() const;
366 
367 #ifdef P_SSL_AES
368 
369  PAESContext & AesEncryptKey() { return m_aesEncryptKey; }
370 
372  PAESContext & AesDecryptKey() { return m_aesDecryptKey; }
373 #endif
374 
375  protected:
378  void CalculateAesKeys();
379 
381  PString encryptionKey;
382 
384  PString challengeKey;
385 
388 
389 #ifdef P_SSL_AES
390 
391  PAESContext m_aesEncryptKey;
392 
394  PAESContext m_aesDecryptKey;
395 #endif
396 };
397 
399 
400 
401 #endif // OPAL_IAX2
402 
403 #endif // OPAL_IAX2_REMOTE_H
404 
405 /* The comment below is magic for those who use emacs to edit this file.
406  * With the comment below, the tab key does auto indent to 2 spaces.
407  *
408  * Local Variables:
409  * mode:c
410  * c-basic-offset:2
411  * End:
412  */