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: 24178 $ 29 * $Author: rjongbloed $ 30 * $Date: 2010-04-05 19:10:56 -0500 (Mon, 05 Apr 2010) $ 31 */ 32 33 #ifndef OPAL_IAX2_REGPROCESSOR_H 34 #define OPAL_IAX2_REGPROCESSOR_H 35 36 #ifndef _PTLIB_H 37 #include <ptlib.h> 38 #endif 39 40 #include <opal/buildopts.h> 41 42 #if OPAL_IAX2 43 44 #include <ptclib/random.h> 45 #include <opal/connection.h> 46 47 #include <iax2/frame.h> 48 #include <iax2/processor.h> 49 #include <iax2/iedata.h> 50 #include <iax2/remote.h> 51 #include <iax2/safestrings.h> 52 #include <iax2/sound.h> 53 54 class IAX2EndPoint; 55 class IAX2Connection; 56 57 class IAX2RegProcessor : public IAX2Processor 58 { 59 PCLASSINFO(IAX2RegProcessor, IAX2Processor); 60 61 public: 62 /**Construct this class */ 63 IAX2RegProcessor( IAX2EndPoint & ep, 64 const PString & host, 65 const PString & username, 66 const PString & password, 67 PINDEX inRegistrationRefreshTime 68 ); 69 70 /**Destructor */ 71 virtual ~IAX2RegProcessor(); 72 73 /**Unregister from the remote iax2 server. This method is synchronous. and could 74 take until the Timeout peroid to return. This will also shutdown 75 the main thread.*/ 76 void Unregister(); 77 GetHost()78 PString GetHost() const { return host; }; GetUserName()79 PString GetUserName() const { return userName; }; GetPassword()80 PString GetPassword() const { return password; }; 81 82 protected: 83 PString host; 84 PString userName; 85 PString password; 86 87 INT registrationRefreshTime; 88 89 /** bit mask of the different flags to indicate call status*/ 90 enum RegistrationState { 91 registrationStart = 1, /*!< Intial state of registration*/ 92 registrationHappening, /*!< The registration process is happening*/ 93 registrationUnregisterStart,/*!< The unregistration process is about to begin*/ 94 registrationUnregistering, /*!< The unregistration process is happening*/ 95 registrationUnregistered, 96 /*!< The unregistration process is complete and is waiting for termination*/ 97 registrationWait /*!< Waiting for the refresh peroid*/ 98 }; 99 100 /** The current state of the registration */ 101 RegistrationState registrationState; 102 103 /** A mutex to protect the registrationState variable and the flow 104 of the RegProcessor.*/ 105 PMutex stateMutex; 106 107 #ifdef DOC_PLUS_PLUS 108 /**A pwlib callback function to start the registration process again */ 109 void OnDoRegistration(PTimer &, INT); 110 #else 111 PDECLARE_NOTIFIER(PTimer, IAX2RegProcessor, OnDoRegistration); 112 #endif 113 114 /** The timer which is used to send a registration message */ 115 PTimer registrationTimer; 116 117 /** Process an authentication request when registering*/ 118 void ProcessIaxCmdRegAuth(IAX2FullFrameProtocol * src); 119 120 /** Process an acknowledgement of a sucessful registration*/ 121 void ProcessIaxCmdRegAck(IAX2FullFrameProtocol * src); 122 123 /** Process a registration rejection*/ 124 void ProcessIaxCmdRegRej(IAX2FullFrameProtocol * src); 125 126 /** Process an authentication request when 127 registering doing a registration release*/ 128 void ProcessIaxCmdUnRegAuth(IAX2FullFrameProtocol * src); 129 130 /** Process an acknowledgement of a registration release*/ 131 void ProcessIaxCmdUnRegAck(IAX2FullFrameProtocol * src); 132 133 /** Process a registration release rejection*/ 134 void ProcessIaxCmdUnRegRej(IAX2FullFrameProtocol * src); 135 136 /**This callback is called when a packet fails to get an 137 Acknowledgment */ 138 void OnNoResponseTimeout(); 139 140 /**A method to cause some of the values in this class to be formatted 141 into a printable stream */ 142 void PrintOn(ostream & strm) const; 143 144 /**Go through the three lists for incoming data (ethernet/sound/UI commands. */ 145 virtual void ProcessLists(); 146 147 /**Processes a full frame, and sends it off to the relevant processor. This RegistrationProcessor instance worries about those types 148 common to registration, so is concerned about cmdRegAuth, cmdRegAck etc.*/ 149 virtual void ProcessFullFrame(IAX2FullFrame & fullFrame); 150 151 /**Handles a mini frame - so copes with media.*/ 152 virtual void ProcessNetworkFrame(IAX2MiniFrame * src); 153 154 /**Processes a protocol full frame, well, those components relating to 155 * registration.*/ 156 virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src); 157 158 /**Reset the call, ie: get a new call source number, 159 put the sequence numbers to 0 and reset the timer. 160 This solves having to create a new thread for every 161 seperate call. 162 */ 163 void ResetCall(); 164 165 /**Test the sequence number of the incoming frame. This is only 166 valid for handling a call. If the message is outof order, the 167 supplied fullframe is deleted. 168 169 @return true if the frame is out of order, which deletes the supplied frame 170 @return false, and does not destroy the supplied frame*/ IncomingMessageOutOfOrder(IAX2FullFrame *)171 virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *) 172 { return false; }; 173 174 175 /**A class that generates random values used for varying 176 the registration timer*/ 177 PRandom regRandom; 178 }; 179 180 181 #endif // OPAL_IAX2 182 183 #endif // OPAL_IAX2_REGPROCESSOR_H 184