inetprot.h

Go to the documentation of this file.
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: 20385 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00029  */
00030 
00031 #ifndef _PINTERNETPROTOCOL
00032 #define _PINTERNETPROTOCOL
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 #ifndef _PTLIB_H
00039 #include <ptlib.h>
00040 #endif
00041 
00042 class PSocket;
00043 class PIPSocket;
00044 
00045 
00065 class PInternetProtocol : public PIndirectChannel
00066 {
00067   PCLASSINFO(PInternetProtocol, PIndirectChannel)
00068 
00069   protected:
00070     PInternetProtocol(
00071       const char * defaultServiceName, 
00072       PINDEX cmdCount,                 
00073       char const * const * cmdNames    
00074     );
00075     // Create an unopened TCP/IP protocol socket channel.
00076 
00077 
00078   public:
00079   // Overrides from class PChannel.
00091     virtual PBoolean Read(
00092       void * buf,   
00093       PINDEX len    
00094     );
00095 
00111     virtual PBoolean Write(
00112       const void * buf, 
00113       PINDEX len        
00114     );
00115 
00119      void SetReadLineTimeout(
00120        const PTimeInterval & t
00121      );
00122 
00123   // New functions for class.
00129     virtual PBoolean Connect(
00130       const PString & address,    
00131       WORD port = 0               
00132     );
00133     virtual PBoolean Connect(
00134       const PString & address,    
00135       const PString & service     
00136     );
00137 
00143     virtual PBoolean Accept(
00144       PSocket & listener    
00145     );
00146 
00153     const PString & GetDefaultService() const;
00154 
00163     PIPSocket * GetSocket() const;
00164 
00172     virtual PBoolean WriteLine(
00173       const PString & line 
00174     );
00175 
00192     virtual PBoolean ReadLine(
00193       PString & line,             
00194       PBoolean allowContinuation = PFalse  
00195     );
00196 
00200     virtual void UnRead(
00201       int ch                
00202     );
00203     virtual void UnRead(
00204       const PString & str   
00205     );
00206     virtual void UnRead(
00207       const void * buffer,  
00208       PINDEX len            
00209     );
00210 
00224     virtual PBoolean WriteCommand(
00225       PINDEX cmdNumber       
00226     );
00227     virtual PBoolean WriteCommand(
00228       PINDEX cmdNumber,      
00229       const PString & param  
00230     );
00231 
00249     virtual PBoolean ReadCommand(
00250       PINDEX & num,
00253       PString & args  
00254     );
00255 
00272     virtual PBoolean WriteResponse(
00273       unsigned numericCode, 
00274       const PString & info  
00275     );
00276     virtual PBoolean WriteResponse(
00277       const PString & code, 
00278       const PString & info  
00279     );
00280 
00299     virtual PBoolean ReadResponse();
00300     virtual PBoolean ReadResponse(
00301       int & code,      
00302       PString & info   
00303     );
00304 
00316     virtual int ExecuteCommand(
00317       PINDEX cmdNumber       
00318     );
00319     virtual int ExecuteCommand(
00320       PINDEX cmdNumber,      
00321       const PString & param  
00322     );
00323 
00330     int GetLastResponseCode() const;
00331 
00337     PString GetLastResponseInfo() const;
00338 
00339 
00340   protected:
00352     virtual PINDEX ParseResponse(
00353       const PString & line 
00354     );
00355 
00356 
00357     PString defaultServiceName;
00358     // Default Service name to use for the internet protocol socket.
00359 
00360     PStringArray commandNames;
00361     // Names of each of the command codes.
00362 
00363     PCharArray unReadBuffer;
00364     // Buffer for characters put back into the data stream.
00365 
00366     PINDEX unReadCount;
00367     // Buffer count for characters put back into the data stream.
00368 
00369     PTimeInterval readLineTimeout;
00370     // Time for characters in a line to be received.
00371 
00372     enum StuffState {
00373       DontStuff, StuffIdle, StuffCR, StuffCRLF, StuffCRLFdot, StuffCRLFdotCR
00374     } stuffingState;
00375     // Do byte stuffing of '.' characters in output to the socket channel.
00376 
00377     PBoolean newLineToCRLF;
00378     // Translate \n characters to CR/LF pairs.
00379 
00380     int     lastResponseCode;
00381     PString lastResponseInfo;
00382     // Responses
00383 
00384   private:
00385     PBoolean AttachSocket(PIPSocket * socket);
00386 };
00387 
00388 
00389 
00390 #endif
00391 
00392 
00393 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Sep 15 01:21:35 2008 for PTLib by  doxygen 1.5.1