PTLib
Version 2.10.4
|
00001 /* 00002 * inetprot.h 00003 * 00004 * Internet Protocol ancestor channel class 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-2002 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Revision: 24177 $ 00027 * $Author: rjongbloed $ 00028 * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $ 00029 */ 00030 00031 #ifndef PTLIB_INETPROT_H 00032 #define PTLIB_INETPROT_H 00033 00034 #ifdef P_USE_PRAGMA 00035 #pragma interface 00036 #endif 00037 00038 00039 class PSocket; 00040 class PIPSocket; 00041 00042 00062 class PInternetProtocol : public PIndirectChannel 00063 { 00064 PCLASSINFO(PInternetProtocol, PIndirectChannel) 00065 00066 protected: 00067 PInternetProtocol( 00068 const char * defaultServiceName, 00069 PINDEX cmdCount, 00070 char const * const * cmdNames 00071 ); 00072 // Create an unopened TCP/IP protocol socket channel. 00073 00074 00075 public: 00076 // Overrides from class PChannel. 00088 virtual PBoolean Read( 00089 void * buf, 00090 PINDEX len 00091 ); 00092 00108 virtual PBoolean Write( 00109 const void * buf, 00110 PINDEX len 00111 ); 00112 00116 void SetReadLineTimeout( 00117 const PTimeInterval & t 00118 ); 00119 00120 // New functions for class. 00126 virtual PBoolean Connect( 00127 const PString & address, 00128 WORD port = 0 00129 ); 00130 virtual PBoolean Connect( 00131 const PString & address, 00132 const PString & service 00133 ); 00134 00140 virtual PBoolean Accept( 00141 PSocket & listener 00142 ); 00143 00150 const PString & GetDefaultService() const; 00151 00160 PIPSocket * GetSocket() const; 00161 00169 virtual PBoolean WriteLine( 00170 const PString & line 00171 ); 00172 00189 virtual PBoolean ReadLine( 00190 PString & line, 00191 PBoolean allowContinuation = false 00192 ); 00193 00197 virtual void UnRead( 00198 int ch 00199 ); 00200 virtual void UnRead( 00201 const PString & str 00202 ); 00203 virtual void UnRead( 00204 const void * buffer, 00205 PINDEX len 00206 ); 00207 00221 virtual PBoolean WriteCommand( 00222 PINDEX cmdNumber 00223 ); 00224 virtual PBoolean WriteCommand( 00225 PINDEX cmdNumber, 00226 const PString & param 00227 ); 00228 00246 virtual PBoolean ReadCommand( 00247 PINDEX & num, 00250 PString & args 00251 ); 00252 00269 virtual PBoolean WriteResponse( 00270 unsigned numericCode, 00271 const PString & info 00272 ); 00273 virtual PBoolean WriteResponse( 00274 const PString & code, 00275 const PString & info 00276 ); 00277 00296 virtual PBoolean ReadResponse(); 00297 virtual PBoolean ReadResponse( 00298 int & code, 00299 PString & info 00300 ); 00301 00313 virtual int ExecuteCommand( 00314 PINDEX cmdNumber 00315 ); 00316 virtual int ExecuteCommand( 00317 PINDEX cmdNumber, 00318 const PString & param 00319 ); 00320 00327 int GetLastResponseCode() const; 00328 00334 PString GetLastResponseInfo() const; 00335 00336 00337 protected: 00349 virtual PINDEX ParseResponse( 00350 const PString & line 00351 ); 00352 00353 00354 PString defaultServiceName; 00355 // Default Service name to use for the internet protocol socket. 00356 00357 PStringArray commandNames; 00358 // Names of each of the command codes. 00359 00360 PCharArray unReadBuffer; 00361 // Buffer for characters put back into the data stream. 00362 00363 PINDEX unReadCount; 00364 // Buffer count for characters put back into the data stream. 00365 00366 PTimeInterval readLineTimeout; 00367 // Time for characters in a line to be received. 00368 00369 enum StuffState { 00370 DontStuff, StuffIdle, StuffCR, StuffCRLF, StuffCRLFdot, StuffCRLFdotCR 00371 } stuffingState; 00372 // Do byte stuffing of '.' characters in output to the socket channel. 00373 00374 PBoolean newLineToCRLF; 00375 // Translate \\n characters to CR/LF pairs. 00376 00377 int lastResponseCode; 00378 PString lastResponseInfo; 00379 // Responses 00380 00381 private: 00382 PBoolean AttachSocket(PIPSocket * socket); 00383 }; 00384 00385 00386 00387 #endif // PTLIB_INETPROT_H 00388 00389 00390 // End Of File ///////////////////////////////////////////////////////////////