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.19 2005/11/30 12:47:37 csoutheren 00028 * Removed tabs, reformatted some code, and changed tags for Doxygen 00029 * 00030 * Revision 1.18 2004/11/11 07:34:50 csoutheren 00031 * Added #include <ptlib.h> 00032 * 00033 * Revision 1.17 2002/11/06 22:47:24 robertj 00034 * Fixed header comment (copyright etc) 00035 * 00036 * Revision 1.16 2002/09/16 01:08:59 robertj 00037 * Added #define so can select if #pragma interface/implementation is used on 00038 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00039 * 00040 * Revision 1.15 2001/09/26 09:37:04 robertj 00041 * Added virtual keyword to a lot of functions so can be overridden. 00042 * 00043 * Revision 1.14 1999/03/09 08:01:46 robertj 00044 * Changed comments for doc++ support (more to come). 00045 * 00046 * Revision 1.13 1999/02/16 08:07:10 robertj 00047 * MSVC 6.0 compatibility changes. 00048 * 00049 * Revision 1.12 1998/09/23 06:19:40 robertj 00050 * Added open source copyright license. 00051 * 00052 * Revision 1.11 1996/09/14 13:09:13 robertj 00053 * Major upgrade: 00054 * rearranged sockets to help support IPX. 00055 * added indirect channel class and moved all protocols to descend from it, 00056 * separating the protocol from the low level byte transport. 00057 * 00058 * Revision 1.10 1996/05/15 10:07:00 robertj 00059 * Added access function to set intercharacter line read timeout. 00060 * 00061 * Revision 1.9 1996/05/09 12:14:02 robertj 00062 * Rewrote the "unread" buffer usage and then used it to improve ReadLine() performance. 00063 * 00064 * Revision 1.8 1996/03/31 08:43:38 robertj 00065 * Added version of WriteCommand() and ExecteCommand() without argument string. 00066 * 00067 * Revision 1.7 1996/03/16 04:35:32 robertj 00068 * Added PString parameter version of UnRead(). 00069 * Changed lastResponseCode to an integer. 00070 * Added ParseReponse() for splitting reponse line into code and info. 00071 * 00072 * Revision 1.6 1996/02/13 12:57:05 robertj 00073 * Added access to the last response in an application socket. 00074 * 00075 * Revision 1.5 1996/02/03 11:33:16 robertj 00076 * Changed RadCmd() so can distinguish between I/O error and unknown command. 00077 * 00078 * Revision 1.4 1996/01/23 13:08:43 robertj 00079 * Major rewrite for HTTP support. 00080 * 00081 * Revision 1.3 1995/06/17 11:12:15 robertj 00082 * Documentation update. 00083 * 00084 * Revision 1.2 1995/06/17 00:39:53 robertj 00085 * More implementation. 00086 * 00087 * Revision 1.1 1995/06/04 13:17:16 robertj 00088 * Initial revision 00089 * 00090 */ 00091 00092 #ifndef _PINTERNETPROTOCOL 00093 #define _PINTERNETPROTOCOL 00094 00095 #ifdef P_USE_PRAGMA 00096 #pragma interface 00097 #endif 00098 00099 #include <ptlib.h> 00100 00101 class PSocket; 00102 class PIPSocket; 00103 00104 00124 class PInternetProtocol : public PIndirectChannel 00125 { 00126 PCLASSINFO(PInternetProtocol, PIndirectChannel) 00127 00128 protected: 00129 PInternetProtocol( 00130 const char * defaultServiceName, 00131 PINDEX cmdCount, 00132 char const * const * cmdNames 00133 ); 00134 // Create an unopened TCP/IP protocol socket channel. 00135 00136 00137 public: 00138 // Overrides from class PChannel. 00150 virtual BOOL Read( 00151 void * buf, 00152 PINDEX len 00153 ); 00154 00170 virtual BOOL Write( 00171 const void * buf, 00172 PINDEX len 00173 ); 00174 00178 void SetReadLineTimeout( 00179 const PTimeInterval & t 00180 ); 00181 00182 // New functions for class. 00188 virtual BOOL Connect( 00189 const PString & address, 00190 WORD port = 0 00191 ); 00192 virtual BOOL Connect( 00193 const PString & address, 00194 const PString & service 00195 ); 00196 00202 virtual BOOL Accept( 00203 PSocket & listener 00204 ); 00205 00212 const PString & GetDefaultService() const; 00213 00222 PIPSocket * GetSocket() const; 00223 00231 virtual BOOL WriteLine( 00232 const PString & line 00233 ); 00234 00251 virtual BOOL ReadLine( 00252 PString & line, 00253 BOOL allowContinuation = FALSE 00254 ); 00255 00259 virtual void UnRead( 00260 int ch 00261 ); 00262 virtual void UnRead( 00263 const PString & str 00264 ); 00265 virtual void UnRead( 00266 const void * buffer, 00267 PINDEX len 00268 ); 00269 00283 virtual BOOL WriteCommand( 00284 PINDEX cmdNumber 00285 ); 00286 virtual BOOL WriteCommand( 00287 PINDEX cmdNumber, 00288 const PString & param 00289 ); 00290 00308 virtual BOOL ReadCommand( 00309 PINDEX & num, 00312 PString & args 00313 ); 00314 00331 virtual BOOL WriteResponse( 00332 unsigned numericCode, 00333 const PString & info 00334 ); 00335 virtual BOOL WriteResponse( 00336 const PString & code, 00337 const PString & info 00338 ); 00339 00358 virtual BOOL ReadResponse(); 00359 virtual BOOL ReadResponse( 00360 int & code, 00361 PString & info 00362 ); 00363 00375 virtual int ExecuteCommand( 00376 PINDEX cmdNumber 00377 ); 00378 virtual int ExecuteCommand( 00379 PINDEX cmdNumber, 00380 const PString & param 00381 ); 00382 00389 int GetLastResponseCode() const; 00390 00396 PString GetLastResponseInfo() const; 00397 00398 00399 protected: 00411 virtual PINDEX ParseResponse( 00412 const PString & line 00413 ); 00414 00415 00416 PString defaultServiceName; 00417 // Default Service name to use for the internet protocol socket. 00418 00419 PStringArray commandNames; 00420 // Names of each of the command codes. 00421 00422 PCharArray unReadBuffer; 00423 // Buffer for characters put back into the data stream. 00424 00425 PINDEX unReadCount; 00426 // Buffer count for characters put back into the data stream. 00427 00428 PTimeInterval readLineTimeout; 00429 // Time for characters in a line to be received. 00430 00431 enum StuffState { 00432 DontStuff, StuffIdle, StuffCR, StuffCRLF, StuffCRLFdot, StuffCRLFdotCR 00433 } stuffingState; 00434 // Do byte stuffing of '.' characters in output to the socket channel. 00435 00436 BOOL newLineToCRLF; 00437 // Translate \n characters to CR/LF pairs. 00438 00439 int lastResponseCode; 00440 PString lastResponseInfo; 00441 // Responses 00442 00443 private: 00444 BOOL AttachSocket(PIPSocket * socket); 00445 }; 00446 00447 00448 00449 #endif 00450 00451 00452 // End Of File ///////////////////////////////////////////////////////////////