OPAL  Version 3.10.10
iax2ep.h
Go to the documentation of this file.
1 /*
2  *
3  * Inter Asterisk Exchange 2
4  *
5  * Open Phone Abstraction Library (OPAL)
6  *
7  * Describes the IAX2 extension of the OpalEndpoint class.
8  *
9  * Copyright (c) 2005 Indranet Technologies Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Open Phone Abstraction Library.
22  *
23  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
24  *
25  * The author of this code is Derek J Smithies
26  *
27  * $Revision: 24719 $
28  * $Author: rjongbloed $
29  * $Date: 2010-09-23 18:55:55 -0500 (Thu, 23 Sep 2010) $
30  */
31 
32 #ifndef OPAL_IAX2_IAX2EP_H
33 #define OPAL_IAX2_IAX2EP_H
34 
35 #ifndef _PTLIB_H
36 #include <ptlib.h>
37 #endif
38 
39 #ifdef P_USE_PRAGMA
40 #pragma interface
41 #endif
42 
43 #include <opal/buildopts.h>
44 
45 #if OPAL_IAX2
46 
47 #include <opal/endpoint.h>
48 #include <iax2/iax2con.h>
49 #include <iax2/processor.h>
50 #include <iax2/regprocessor.h>
51 #include <iax2/specialprocessor.h>
52 
53 class IAX2Receiver;
54 class IAX2Transmit;
55 class IAX2Processor;
56 
60 class IAX2IncomingEthernetFrames : public PThread
61 {
62  PCLASSINFO(IAX2IncomingEthernetFrames, PThread);
63 public:
64 
69 
72 
75  /*The method which gets everythig to happen */
76  virtual void Main();
77 
79  void Assign(IAX2EndPoint *ep);
80 
83  void ProcessList() { activate.Signal(); }
84 
86  void Terminate();
87 
89  protected:
92 
94  PSyncPoint activate;
95 
97  PBoolean keepGoing;
98 };
99 
100 
101 
102 
105 {
106  PCLASSINFO(IAX2EndPoint, OpalEndPoint);
107  public:
112  IAX2EndPoint(
113  OpalManager & manager,
114  unsigned short port = 4569
115  );
116 
118  ~IAX2EndPoint();
120 
127  virtual PBoolean NewIncomingConnection(
128  OpalTransport * transport
129  );
130 
160  virtual PSafePtr<OpalConnection> MakeConnection(
161  OpalCall & call,
162  const PString & party,
163  void * userData = NULL,
164  unsigned int options = 0,
165  OpalConnection::StringOptions * stringOptions = NULL
166  );
167 
171  virtual IAX2Connection * CreateConnection(
172  OpalCall & call,
173  const PString & token,
174  void * userData,
175  const PString & remoteParty,
176  const PString & remotePartyName = PString::Empty()
177  );
179 
184  PBoolean Initialise();
185 
187  virtual void IncomingEthernetFrame (IAX2Frame *frame);
188 
194  PBoolean ConectionForFrameIsAlive(IAX2Frame *f);
195 
202  PINDEX NextSrcCallNumber(IAX2Processor * processor);
203 
206  void ReportStoredConnections();
207 
209  WORD ListenPortNumber() { return 4569; }
210 
213 
216 
218  PString GetLocalUserName() { return localUserName; }
219 
221  PString GetLocalNumber() { return localNumber; }
222 
224  void SetLocalUserName(PString newValue);
225 
227  void SetLocalNumber(PString newValue);
228 
230  PString & GetPassword() { return password; }
231 
233  void SetPassword(PString newValue);
234 
241  PBoolean ConnectionForFrameIsAlive(IAX2Frame *f);
242 
244  PINDEX GetOutSequenceNumberForStatusQuery();
245 
247  void StartRinging(PString remoteCaller);
248 
260  void NewIncomingConnection(
261  IAX2Frame *f
262  );
263 
269  void OnEstablished(
270  OpalConnection & con
271  );
272 
278  virtual void OnReleased(
279  OpalConnection & connection
280  );
281 
291  virtual OpalMediaFormatList GetMediaFormats() const;
292 
294  PINDEX GetSupportedCodecs(OpalMediaFormatList & list);
295 
297  PINDEX GetPreferredCodec(OpalMediaFormatList & list);
298 
301  void GetCodecLengths(PINDEX src, PINDEX &compressedBytes, PINDEX &duration);
302 
309  protoIndex = 0,
310  userIndex = 1,
311  transportIndex = 2,
312  addressIndex = 3,
313  portIndex = 4,
314  extensionIndex = 5,
315  contextIndex = 6,
316  maximumIndex = 7
317  };
318 
325  static PStringArray DissectRemoteParty(const PString & other);
326 
330  void ProcessReceivedEthernetFrames();
331 
334  void ReportTransmitterLists(PString & answer, bool getFullReport = false);
335 
337  void CopyLocalMediaFormats(OpalMediaFormatList & list);
338 
344  void Register(
345  const PString & host,
346  const PString & username,
347  const PString & password = PString::Empty(),
348  PINDEX requestedRefreshTime = 60
349  );
350 
352  RegisteredFailureUnknown
353  };
354 
357  virtual void OnRegistered(
358  const PString & host,
359  const PString & userName,
360  PBoolean isFailure,
361  RegisteredError reason = RegisteredFailureUnknown);
362 
365  void Unregister(
366  const PString & host,
367  const PString & username);
368 
370  UnregisteredFailureUnknown
371  };
372 
377  virtual void OnUnregistered(
378  const PString & host,
379  const PString & userName,
380  PBoolean isFailure,
381  UnregisteredError reason = UnregisteredFailureUnknown);
382 
383 
385  PBoolean IsRegistered(const PString & host, const PString & username);
386 
388  PINDEX GetRegistrationsCount();
389 
391  PString BuildUrl(
392  const PString & host,
393  const PString & userName = PString::Empty(),
394  const PString & extension = PString::Empty(),
395  const PString & context = PString::Empty(),
396  const PString & transport = PString::Empty()
397  );
398 
400  PBoolean InitialisedOK() { return (transmitter != NULL) && (receiver != NULL); }
401 
405  { return packetsReadFromEthernet.GetSize() > 0; }
407 
408  protected:
416 
420 
422  PUDPSocket *sock;
423 
425  unsigned short localPort;
426 
429 
431  PMutex callNumbLock;
432 
435 
437  PString localUserName;
438 
440  PString localNumber;
441 
443  PString password;
444 
447 
450 
454 
462  PBoolean ProcessInMatchingConnection(IAX2Frame *f);
463 
472  PBoolean ProcessFrameInConnection(IAX2Frame *f, const PString & token);
473 
480  PBoolean ProcessInConnectionTestAll(IAX2Frame *f);
481 
494  PStringToString tokenTable;
495 
499  PReadWriteMutex mutexTokenTable;
500 
503  PAtomicInteger callsEstablished;
504 
507 
510 
515  PArrayObjects regProcessors;
516 
517 };
518 
519 
520 #endif // OPAL_IAX2
521 
522 #endif // OPAL_IAX2_IAX2EP_H
523 
524 /* The comment below is magic for those who use emacs to edit this file.
525  * With the comment below, the tab key does auto indent to 2 spaces.
526  *
527  * Local Variables:
528  * mode:c
529  * c-basic-offset:2
530  * End:
531  */
532 
IAX2RemoteAddressFields
Definition: iax2ep.h:308
OpalMediaFormatList localMediaFormats
Definition: iax2ep.h:506
Definition: manager.h:74
PBoolean keepGoing
Definition: iax2ep.h:97
Definition: endpoint.h:67
PMutex callNumbLock
Definition: iax2ep.h:431
void Assign(IAX2EndPoint *ep)
Definition: frame.h:1168
PString password
Definition: iax2ep.h:443
PString localUserName
Definition: iax2ep.h:437
Definition: iax2ep.h:104
PStringToString tokenTable
Definition: iax2ep.h:494
Definition: transports.h:703
Definition: iax2con.h:63
Definition: transmit.h:63
PString localNumber
Definition: iax2ep.h:440
PArrayObjects regProcessors
Definition: iax2ep.h:515
PBoolean InitialisedOK()
Definition: iax2ep.h:400
Definition: specialprocessor.h:56
WORD ListenPortNumber()
Definition: iax2ep.h:209
PBoolean EthernetFramesToBeProcessed()
Definition: iax2ep.h:404
PString GetLocalUserName()
Definition: iax2ep.h:218
IAX2Transmit * transmitter
Definition: iax2ep.h:212
Definition: mediafmt.h:72
Definition: connection.h:462
PAtomicInteger callsEstablished
Definition: iax2ep.h:503
void ProcessList()
Definition: iax2ep.h:83
PSyncPoint activate
Definition: iax2ep.h:94
RegisteredError
Definition: iax2ep.h:351
Definition: iax2ep.h:60
PReadWriteMutex mutexTokenTable
Definition: iax2ep.h:499
PMutex statusQueryMutex
Definition: iax2ep.h:449
Definition: call.h:65
~IAX2IncomingEthernetFrames()
Definition: iax2ep.h:71
IAX2FrameList packetsReadFromEthernet
Definition: iax2ep.h:419
PMutex regProcessorsMutex
Definition: iax2ep.h:509
Definition: processor.h:136
IAX2EndPoint * endpoint
Definition: iax2ep.h:91
IAX2SpecialProcessor * specialPacketHandler
Definition: iax2ep.h:453
int callnumbs
Definition: iax2ep.h:428
Definition: connection.h:353
PString & GetPassword()
Definition: iax2ep.h:230
unsigned short localPort
Definition: iax2ep.h:425
PString GetLocalNumber()
Definition: iax2ep.h:221
Definition: frame.h:75
PINDEX statusQueryCounter
Definition: iax2ep.h:446
PTime callStartTime
Definition: iax2ep.h:434
IAX2Receiver * receiver
Definition: iax2ep.h:215
IAX2IncomingEthernetFrames incomingFrameHandler
Definition: iax2ep.h:415
Definition: receiver.h:60
PUDPSocket * sock
Definition: iax2ep.h:422
UnregisteredError
Definition: iax2ep.h:369