OPAL
Version 3.10.4
|
00001 /* 00002 * 00003 * Inter Asterisk Exchange 2 00004 * 00005 * The core routine which determines the processing of packets for one call. 00006 * 00007 * Open Phone Abstraction Library (OPAL) 00008 * 00009 * Copyright (c) 2005 Indranet Technologies Ltd. 00010 * 00011 * The contents of this file are subject to the Mozilla Public License 00012 * Version 1.0 (the "License"); you may not use this file except in 00013 * compliance with the License. You may obtain a copy of the License at 00014 * http://www.mozilla.org/MPL/ 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" 00017 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00018 * the License for the specific language governing rights and limitations 00019 * under the License. 00020 * 00021 * The Original Code is Open Phone Abstraction Library. 00022 * 00023 * The Initial Developer of the Original Code is Indranet Technologies Ltd. 00024 * 00025 * The author of this code is Derek J Smithies 00026 * 00027 * $Revision: 24178 $ 00028 * $Author: rjongbloed $ 00029 * $Date: 2010-04-05 19:10:56 -0500 (Mon, 05 Apr 2010) $ 00030 */ 00031 00032 #ifndef OPAL_IAX2_PROCESSOR_H 00033 #define OPAL_IAX2_PROCESSOR_H 00034 00035 #ifndef _PTLIB_H 00036 #include <ptlib.h> 00037 #endif 00038 00039 #include <opal/buildopts.h> 00040 00041 #if OPAL_IAX2 00042 00043 #include <opal/connection.h> 00044 00045 #include <iax2/frame.h> 00046 #include <iax2/iedata.h> 00047 #include <iax2/remote.h> 00048 #include <iax2/safestrings.h> 00049 #include <iax2/sound.h> 00050 00051 class IAX2EndPoint; 00052 class IAX2Connection; 00053 class IAX2ThreadHelper; 00054 00056 00077 class IAX2WaitingForAck : public PObject 00078 { 00079 PCLASSINFO(IAX2WaitingForAck, PObject); 00080 00081 public: 00083 enum ResponseToAck { 00084 RingingAcked = 0, 00085 AcceptAcked = 1, 00086 AuthRepAcked = 2, 00087 AnswerAcked = 3 00088 }; 00089 00091 IAX2WaitingForAck(); 00092 00094 void Assign(IAX2FullFrame *f, ResponseToAck _response); 00095 00097 PBoolean MatchingAckPacket(IAX2FullFrame *f); 00098 00100 ResponseToAck GetResponse() { return response; } 00101 00103 PString GetResponseAsString() const; 00104 00106 virtual void PrintOn(ostream & strm) const; 00107 00109 void ZeroValues(); 00110 00111 private: 00113 DWORD timeStamp; 00114 00116 PINDEX seqNo; 00117 00119 ResponseToAck response; 00120 }; 00121 00123 00136 class IAX2Processor : public PThread 00137 { 00138 PCLASSINFO(IAX2Processor, PObject); 00139 00140 public: 00142 IAX2Processor(IAX2EndPoint & ep); 00143 00145 virtual ~IAX2Processor(); 00146 00148 IAX2SequenceNumbers & GetSequenceInfo() { return sequence; } 00149 00151 IAX2Encryption & GetEncryptionInfo() { return encryption; } 00152 00154 void IncomingEthernetFrame (IAX2Frame *frame); 00155 00158 virtual void PrintOn(ostream & strm) const = 0; 00159 00161 IAX2EndPoint & GetEndPoint() { return endpoint; }; 00162 00172 void SetCallToken(const PString & newToken); 00173 00175 PString GetCallToken(); 00176 00178 IAX2Remote & GetRemoteInfo() { return remote; } 00179 00181 const PTimeInterval & GetCallStartTick() { return callStartTick; } 00182 00186 void Main(); 00187 00190 PBoolean IsStatusQueryEthernetFrame(IAX2Frame *frame); 00191 00194 void SetSpecialPackets(PBoolean newValue) { specialPackets = newValue; } 00195 00197 void Terminate(); 00198 00203 void Activate(); 00204 00211 virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff)= 0; 00212 00214 void ReportLists(PString & answer); 00215 00216 protected: 00217 00219 IAX2EndPoint & endpoint; 00220 00224 PTimeInterval callStartTick; 00225 00227 IAX2Remote remote; 00228 00231 void StartNoResponseTimer(PINDEX msToWait = 60000); 00232 00234 void StopNoResponseTimer() { noResponseTimer.Stop(); } 00235 00237 PTimer noResponseTimer; 00238 00240 void CleanPendingLists() { activate.Signal(); } 00241 00244 IAX2WaitingForAck nextTask; 00245 00247 PSyncPoint activate; 00248 00250 PBoolean endThread; 00251 00253 IAX2Encryption encryption; 00254 00256 IAX2SequenceNumbers sequence; 00257 00259 IAX2ActiveFrameList frameList; 00260 00263 SafeString callToken; 00264 00266 virtual void OnNoResponseTimeout() = 0; 00267 00270 enum DefinedNoResponseTimePeriod { 00271 NoResponseTimePeriod = 5000 00272 }; 00273 00277 PBoolean IsHandlingSpecialPackets() { return specialPackets; }; 00278 00281 PBoolean specialPackets; 00282 00285 virtual void ProcessLists() = 0; 00286 00289 virtual void ProcessFullFrame(IAX2FullFrame & fullFrame) = 0; 00290 00293 virtual void ProcessIaxCmdLagRq(IAX2FullFrameProtocol *src); 00294 00297 virtual void ProcessIaxCmdLagRp(IAX2FullFrameProtocol *src); 00298 00301 virtual void ProcessIaxCmdVnak(IAX2FullFrameProtocol *src); 00302 00305 virtual void ProcessIaxCmdPing(IAX2FullFrameProtocol *src); 00306 00309 virtual void ProcessIaxCmdPong(IAX2FullFrameProtocol *src); 00310 00314 PBoolean ProcessOneIncomingEthernetFrame(); 00315 00317 PAtomicInteger controlFramesSent; 00318 00320 PAtomicInteger controlFramesRcvd; 00321 00323 void IncControlFramesSent() { ++controlFramesSent; } 00324 00326 void IncControlFramesRcvd() { ++controlFramesRcvd; } 00327 00330 virtual void ProcessNetworkFrame(IAX2MiniFrame * src) = 0; 00331 00332 /* A frame of FullFrameProtocol type is labelled as AST_FRAME_IAX in the 00333 asterisk souces, It will contain 0, 1, 2 or more Information Elements 00334 (Ie) in the data section. This processor is used to do things that are 00335 common to registration and call handling. 00336 00337 This method will eat/delete the supplied frame. Return true on success, 00338 false on failure.*/ 00339 virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src); 00340 00344 void TransmitFrameToRemoteEndpoint(IAX2Frame *src); 00345 00351 void TransmitFrameToRemoteEndpoint(IAX2FullFrame *src, 00352 IAX2WaitingForAck::ResponseToAck response 00353 ); 00354 00358 void TransmitFrameNow(IAX2Frame *src); 00359 00361 void TransmitFrameToRemoteEndpoint(IAX2FullFrameProtocol *src); 00362 00365 PBoolean Authenticate(IAX2FullFrameProtocol *reply, 00366 PString & password 00367 ); 00368 00370 IAX2IeData ieData; 00371 00374 void SendAckFrame(IAX2FullFrame *inReplyTo); 00375 00379 void SendVnakFrame(IAX2FullFrame *inReplyTo); 00380 00382 void SendUnsupportedFrame(IAX2FullFrame *inReplyTo); 00383 00384 private: 00385 #ifdef DOC_PLUS_PLUS 00386 00393 void OnNoResponseTimeoutStart(PTimer &, INT); 00394 #else 00395 PDECLARE_NOTIFIER(PTimer, IAX2Processor, OnNoResponseTimeoutStart); 00396 #endif 00397 00398 protected: 00405 DWORD currentSoundTimeStamp; 00406 }; 00407 00408 00409 #endif // OPAL_IAX2 00410 00411 #endif // OPAL_IAX2_PROCESSOR_H