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 * $Log: inetprot.h,v $ 00027 * Revision 1.20 2007/04/18 23:49:50 csoutheren 00028 * Add usage of precompiled headers 00029 * 00030 * Revision 1.19 2005/11/30 12:47:37 csoutheren 00031 * Removed tabs, reformatted some code, and changed tags for Doxygen 00032 * 00033 * Revision 1.18 2004/11/11 07:34:50 csoutheren 00034 * Added #include <ptlib.h> 00035 * 00036 * Revision 1.17 2002/11/06 22:47:24 robertj 00037 * Fixed header comment (copyright etc) 00038 * 00039 * Revision 1.16 2002/09/16 01:08:59 robertj 00040 * Added #define so can select if #pragma interface/implementation is used on 00041 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00042 * 00043 * Revision 1.15 2001/09/26 09:37:04 robertj 00044 * Added virtual keyword to a lot of functions so can be overridden. 00045 * 00046 * Revision 1.14 1999/03/09 08:01:46 robertj 00047 * Changed comments for doc++ support (more to come). 00048 * 00049 * Revision 1.13 1999/02/16 08:07:10 robertj 00050 * MSVC 6.0 compatibility changes. 00051 * 00052 * Revision 1.12 1998/09/23 06:19:40 robertj 00053 * Added open source copyright license. 00054 * 00055 * Revision 1.11 1996/09/14 13:09:13 robertj 00056 * Major upgrade: 00057 * rearranged sockets to help support IPX. 00058 * added indirect channel class and moved all protocols to descend from it, 00059 * separating the protocol from the low level byte transport. 00060 * 00061 * Revision 1.10 1996/05/15 10:07:00 robertj 00062 * Added access function to set intercharacter line read timeout. 00063 * 00064 * Revision 1.9 1996/05/09 12:14:02 robertj 00065 * Rewrote the "unread" buffer usage and then used it to improve ReadLine() performance. 00066 * 00067 * Revision 1.8 1996/03/31 08:43:38 robertj 00068 * Added version of WriteCommand() and ExecteCommand() without argument string. 00069 * 00070 * Revision 1.7 1996/03/16 04:35:32 robertj 00071 * Added PString parameter version of UnRead(). 00072 * Changed lastResponseCode to an integer. 00073 * Added ParseReponse() for splitting reponse line into code and info. 00074 * 00075 * Revision 1.6 1996/02/13 12:57:05 robertj 00076 * Added access to the last response in an application socket. 00077 * 00078 * Revision 1.5 1996/02/03 11:33:16 robertj 00079 * Changed RadCmd() so can distinguish between I/O error and unknown command. 00080 * 00081 * Revision 1.4 1996/01/23 13:08:43 robertj 00082 * Major rewrite for HTTP support. 00083 * 00084 * Revision 1.3 1995/06/17 11:12:15 robertj 00085 * Documentation update. 00086 * 00087 * Revision 1.2 1995/06/17 00:39:53 robertj 00088 * More implementation. 00089 * 00090 * Revision 1.1 1995/06/04 13:17:16 robertj 00091 * Initial revision 00092 * 00093 */ 00094 00095 #ifndef _PINTERNETPROTOCOL 00096 #define _PINTERNETPROTOCOL 00097 00098 #ifdef P_USE_PRAGMA 00099 #pragma interface 00100 #endif 00101 00102 #ifndef _PTLIB_H 00103 #include <ptlib.h> 00104 #endif 00105 00106 class PSocket; 00107 class PIPSocket; 00108 00109 00129 class PInternetProtocol : public PIndirectChannel 00130 { 00131 PCLASSINFO(PInternetProtocol, PIndirectChannel) 00132 00133 protected: 00134 PInternetProtocol( 00135 const char * defaultServiceName, 00136 PINDEX cmdCount, 00137 char const * const * cmdNames 00138 ); 00139 // Create an unopened TCP/IP protocol socket channel. 00140 00141 00142 public: 00143 // Overrides from class PChannel. 00155 virtual BOOL Read( 00156 void * buf, 00157 PINDEX len 00158 ); 00159 00175 virtual BOOL Write( 00176 const void * buf, 00177 PINDEX len 00178 ); 00179 00183 void SetReadLineTimeout( 00184 const PTimeInterval & t 00185 ); 00186 00187 // New functions for class. 00193 virtual BOOL Connect( 00194 const PString & address, 00195 WORD port = 0 00196 ); 00197 virtual BOOL Connect( 00198 const PString & address, 00199 const PString & service 00200 ); 00201 00207 virtual BOOL Accept( 00208 PSocket & listener 00209 ); 00210 00217 const PString & GetDefaultService() const; 00218 00227 PIPSocket * GetSocket() const; 00228 00236 virtual BOOL WriteLine( 00237 const PString & line 00238 ); 00239 00256 virtual BOOL ReadLine( 00257 PString & line, 00258 BOOL allowContinuation = FALSE 00259 ); 00260 00264 virtual void UnRead( 00265 int ch 00266 ); 00267 virtual void UnRead( 00268 const PString & str 00269 ); 00270 virtual void UnRead( 00271 const void * buffer, 00272 PINDEX len 00273 ); 00274 00288 virtual BOOL WriteCommand( 00289 PINDEX cmdNumber 00290 ); 00291 virtual BOOL WriteCommand( 00292 PINDEX cmdNumber, 00293 const PString & param 00294 ); 00295 00313 virtual BOOL ReadCommand( 00314 PINDEX & num, 00317 PString & args 00318 ); 00319 00336 virtual BOOL WriteResponse( 00337 unsigned numericCode, 00338 const PString & info 00339 ); 00340 virtual BOOL WriteResponse( 00341 const PString & code, 00342 const PString & info 00343 ); 00344 00363 virtual BOOL ReadResponse(); 00364 virtual BOOL ReadResponse( 00365 int & code, 00366 PString & info 00367 ); 00368 00380 virtual int ExecuteCommand( 00381 PINDEX cmdNumber 00382 ); 00383 virtual int ExecuteCommand( 00384 PINDEX cmdNumber, 00385 const PString & param 00386 ); 00387 00394 int GetLastResponseCode() const; 00395 00401 PString GetLastResponseInfo() const; 00402 00403 00404 protected: 00416 virtual PINDEX ParseResponse( 00417 const PString & line 00418 ); 00419 00420 00421 PString defaultServiceName; 00422 // Default Service name to use for the internet protocol socket. 00423 00424 PStringArray commandNames; 00425 // Names of each of the command codes. 00426 00427 PCharArray unReadBuffer; 00428 // Buffer for characters put back into the data stream. 00429 00430 PINDEX unReadCount; 00431 // Buffer count for characters put back into the data stream. 00432 00433 PTimeInterval readLineTimeout; 00434 // Time for characters in a line to be received. 00435 00436 enum StuffState { 00437 DontStuff, StuffIdle, StuffCR, StuffCRLF, StuffCRLFdot, StuffCRLFdotCR 00438 } stuffingState; 00439 // Do byte stuffing of '.' characters in output to the socket channel. 00440 00441 BOOL newLineToCRLF; 00442 // Translate \n characters to CR/LF pairs. 00443 00444 int lastResponseCode; 00445 PString lastResponseInfo; 00446 // Responses 00447 00448 private: 00449 BOOL AttachSocket(PIPSocket * socket); 00450 }; 00451 00452 00453 00454 #endif 00455 00456 00457 // End Of File ///////////////////////////////////////////////////////////////