inetprot.h
Go to the documentation of this file.
/*
* inetprot.h
*
* Internet Protocol ancestor channel class
*
* Portable Windows Library
*
* Copyright (c) 1993-2002 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Contributor(s): ______________________________________.
*
* $Revision: 24177 $
* $Author: rjongbloed $
* $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
*/
#ifndef PTLIB_INETPROT_H
#define PTLIB_INETPROT_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
class PSocket;
class PIPSocket;
class PInternetProtocol : public PIndirectChannel
{
PCLASSINFO(PInternetProtocol, PIndirectChannel)
protected:
PInternetProtocol(
const char * defaultServiceName,
PINDEX cmdCount,
char const * const * cmdNames
);
// Create an unopened TCP/IP protocol socket channel.
public:
// Overrides from class PChannel.
virtual PBoolean Read(
void * buf,
PINDEX len
);
virtual PBoolean Write(
const void * buf,
PINDEX len
);
void SetReadLineTimeout(
const PTimeInterval & t
);
// New functions for class.
virtual PBoolean Connect(
const PString & address,
WORD port = 0
);
virtual PBoolean Connect(
const PString & address,
const PString & service
);
virtual PBoolean Accept(
PSocket & listener
);
const PString & GetDefaultService() const;
PIPSocket * GetSocket() const;
virtual PBoolean WriteLine(
const PString & line
);
virtual PBoolean ReadLine(
PString & line,
PBoolean allowContinuation = false
);
virtual void UnRead(
int ch
);
virtual void UnRead(
const PString & str
);
virtual void UnRead(
const void * buffer,
PINDEX len
);
virtual PBoolean WriteCommand(
PINDEX cmdNumber
);
virtual PBoolean WriteCommand(
PINDEX cmdNumber,
const PString & param
);
virtual PBoolean ReadCommand(
PINDEX & num,
PString & args
);
virtual PBoolean WriteResponse(
unsigned numericCode,
const PString & info
);
virtual PBoolean WriteResponse(
const PString & code,
const PString & info
);
virtual PBoolean ReadResponse();
virtual PBoolean ReadResponse(
int & code,
PString & info
);
virtual int ExecuteCommand(
PINDEX cmdNumber
);
virtual int ExecuteCommand(
PINDEX cmdNumber,
const PString & param
);
int GetLastResponseCode() const;
PString GetLastResponseInfo() const;
protected:
virtual PINDEX ParseResponse(
const PString & line
);
PString defaultServiceName;
// Default Service name to use for the internet protocol socket.
PStringArray commandNames;
// Names of each of the command codes.
PCharArray unReadBuffer;
// Buffer for characters put back into the data stream.
PINDEX unReadCount;
// Buffer count for characters put back into the data stream.
PTimeInterval readLineTimeout;
// Time for characters in a line to be received.
enum StuffState {
DontStuff, StuffIdle, StuffCR, StuffCRLF, StuffCRLFdot, StuffCRLFdotCR
} stuffingState;
// Do byte stuffing of '.' characters in output to the socket channel.
PBoolean newLineToCRLF;
// Translate \\n characters to CR/LF pairs.
int lastResponseCode;
PString lastResponseInfo;
// Responses
private:
PBoolean AttachSocket(PIPSocket * socket);
};
#endif // PTLIB_INETPROT_H
// End Of File ///////////////////////////////////////////////////////////////
PInternetProtocol::WriteCommand
virtual PBoolean WriteCommand(PINDEX cmdNumber)
Write a single line for a command.
PTimeInterval
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
PInternetProtocol::ReadCommand
virtual PBoolean ReadCommand(PINDEX &num, PString &args)
Read a single line of a command which ends with a CR/LF pair.
PCharArray
Array of characters.
Definition: array.h:551
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PInternetProtocol::GetLastResponseCode
int GetLastResponseCode() const
Return the code associated with the last response received by the socket.
PInternetProtocol::lastResponseCode
int lastResponseCode
Definition: inetprot.h:377
PInternetProtocol::GetLastResponseInfo
PString GetLastResponseInfo() const
Return the last response received by the socket.
PInternetProtocol::unReadBuffer
PCharArray unReadBuffer
Definition: inetprot.h:360
PInternetProtocol::unReadCount
PINDEX unReadCount
Definition: inetprot.h:363
PIPSocket
This class describes a type of socket that will communicate using the Internet Protocol.
Definition: ipsock.h:63
PInternetProtocol::StuffCRLF
Definition: inetprot.h:370
PInternetProtocol::StuffIdle
Definition: inetprot.h:370
PIndirectChannel
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:49
PStringArray
This is an array collection class of PString objects.
Definition: pstring.h:2024
PInternetProtocol::WriteResponse
virtual PBoolean WriteResponse(unsigned numericCode, const PString &info)
Write a response code followed by a text string describing the response to a command.
PInternetProtocol::ExecuteCommand
virtual int ExecuteCommand(PINDEX cmdNumber)
Write a command to the socket, using WriteCommand() and await a response using ReadResponse().
PInternetProtocol::StuffCRLFdot
Definition: inetprot.h:370
PInternetProtocol::defaultServiceName
PString defaultServiceName
Definition: inetprot.h:354
PInternetProtocol
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:62
PBoolean
BOOL PBoolean
Definition: object.h:102
PInternetProtocol::newLineToCRLF
PBoolean newLineToCRLF
Definition: inetprot.h:374
PInternetProtocol::SetReadLineTimeout
void SetReadLineTimeout(const PTimeInterval &t)
Set the maximum timeout between characters within a line.
PInternetProtocol::stuffingState
enum PInternetProtocol::StuffState stuffingState
PInternetProtocol::commandNames
PStringArray commandNames
Definition: inetprot.h:357
PInternetProtocol::DontStuff
Definition: inetprot.h:370
PInternetProtocol::WriteLine
virtual PBoolean WriteLine(const PString &line)
Write a string to the socket channel followed by a CR/LF pair.
PString
The character string class.
Definition: pstring.h:108
PInternetProtocol::Connect
virtual PBoolean Connect(const PString &address, WORD port=0)
Connect a socket to a remote host for the internet protocol.
PInternetProtocol::StuffCR
Definition: inetprot.h:370
PInternetProtocol::lastResponseInfo
PString lastResponseInfo
Definition: inetprot.h:378
PInternetProtocol::UnRead
virtual void UnRead(int ch)
Put back the characters into the data stream so that the next Read() function call will return them f...
PInternetProtocol::StuffCRLFdotCR
Definition: inetprot.h:370
PInternetProtocol::PInternetProtocol
PInternetProtocol(const char *defaultServiceName, PINDEX cmdCount, char const *const *cmdNames)
PInternetProtocol::GetSocket
PIPSocket * GetSocket() const
Get the eventual socket for the series of indirect channels that may be between the current protocol ...
PInternetProtocol::GetDefaultService
const PString & GetDefaultService() const
Get the default service name or port number to use in socket connections.
PInternetProtocol::StuffState
StuffState
Definition: inetprot.h:369
PInternetProtocol::Write
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
PInternetProtocol::ReadResponse
virtual PBoolean ReadResponse()
Read a response code followed by a text string describing the response to a command.
PSocket
A network communications channel.
Definition: socket.h:58
PInternetProtocol::Read
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PInternetProtocol::readLineTimeout
PTimeInterval readLineTimeout
Definition: inetprot.h:366
PInternetProtocol::ReadLine
virtual PBoolean ReadLine(PString &line, PBoolean allowContinuation=false)
Read a string from the socket channel up to a CR/LF pair.
PInternetProtocol::ParseResponse
virtual PINDEX ParseResponse(const PString &line)
Parse a response line string into a response code and any extra info on the line. ...
PInternetProtocol::Accept
virtual PBoolean Accept(PSocket &listener)
Accept a server socket to a remote host for the internet protocol.