PTLib  Version 2.10.11
inetprot.h
Go to the documentation of this file.
1 /*
2  * inetprot.h
3  *
4  * Internet Protocol ancestor channel class
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 24177 $
27  * $Author: rjongbloed $
28  * $Date: 2010-04-05 06:52:04 -0500 (Mon, 05 Apr 2010) $
29  */
30 
31 #ifndef PTLIB_INETPROT_H
32 #define PTLIB_INETPROT_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 
39 class PSocket;
40 class PIPSocket;
41 
42 
63 {
65 
66  protected:
68  const char * defaultServiceName,
69  PINDEX cmdCount,
70  char const * const * cmdNames
71  );
72  // Create an unopened TCP/IP protocol socket channel.
73 
74 
75  public:
76  // Overrides from class PChannel.
88  virtual PBoolean Read(
89  void * buf,
90  PINDEX len
91  );
92 
108  virtual PBoolean Write(
109  const void * buf,
110  PINDEX len
111  );
112 
116  void SetReadLineTimeout(
117  const PTimeInterval & t
118  );
119 
120  // New functions for class.
126  virtual PBoolean Connect(
127  const PString & address,
128  WORD port = 0
129  );
130  virtual PBoolean Connect(
131  const PString & address,
132  const PString & service
133  );
134 
140  virtual PBoolean Accept(
141  PSocket & listener
142  );
143 
150  const PString & GetDefaultService() const;
151 
160  PIPSocket * GetSocket() const;
161 
169  virtual PBoolean WriteLine(
170  const PString & line
171  );
172 
189  virtual PBoolean ReadLine(
190  PString & line,
191  PBoolean allowContinuation = false
192  );
193 
197  virtual void UnRead(
198  int ch
199  );
200  virtual void UnRead(
201  const PString & str
202  );
203  virtual void UnRead(
204  const void * buffer,
205  PINDEX len
206  );
207 
221  virtual PBoolean WriteCommand(
222  PINDEX cmdNumber
223  );
224  virtual PBoolean WriteCommand(
225  PINDEX cmdNumber,
226  const PString & param
227  );
228 
246  virtual PBoolean ReadCommand(
247  PINDEX & num,
250  PString & args
251  );
252 
269  virtual PBoolean WriteResponse(
270  unsigned numericCode,
271  const PString & info
272  );
273  virtual PBoolean WriteResponse(
274  const PString & code,
275  const PString & info
276  );
277 
296  virtual PBoolean ReadResponse();
297  virtual PBoolean ReadResponse(
298  int & code,
299  PString & info
300  );
301 
313  virtual int ExecuteCommand(
314  PINDEX cmdNumber
315  );
316  virtual int ExecuteCommand(
317  PINDEX cmdNumber,
318  const PString & param
319  );
320 
327  int GetLastResponseCode() const;
328 
335 
336 
337  protected:
349  virtual PINDEX ParseResponse(
350  const PString & line
351  );
352 
353 
355  // Default Service name to use for the internet protocol socket.
356 
358  // Names of each of the command codes.
359 
361  // Buffer for characters put back into the data stream.
362 
363  PINDEX unReadCount;
364  // Buffer count for characters put back into the data stream.
365 
367  // Time for characters in a line to be received.
368 
369  enum StuffState {
371  } stuffingState;
372  // Do byte stuffing of '.' characters in output to the socket channel.
373 
375  // Translate \\n characters to CR/LF pairs.
376 
379  // Responses
380 
381  private:
382  PBoolean AttachSocket(PIPSocket * socket);
383 };
384 
385 
386 
387 #endif // PTLIB_INETPROT_H
388 
389 
390 // End Of File ///////////////////////////////////////////////////////////////
virtual PBoolean WriteCommand(PINDEX cmdNumber)
Write a single line for a command.
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
virtual PBoolean ReadCommand(PINDEX &num, PString &args)
Read a single line of a command which ends with a CR/LF pair.
Array of characters.
Definition: array.h:551
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
int GetLastResponseCode() const
Return the code associated with the last response received by the socket.
int lastResponseCode
Definition: inetprot.h:377
PString GetLastResponseInfo() const
Return the last response received by the socket.
PCharArray unReadBuffer
Definition: inetprot.h:360
PINDEX unReadCount
Definition: inetprot.h:363
This class describes a type of socket that will communicate using the Internet Protocol.
Definition: ipsock.h:63
Definition: inetprot.h:370
Definition: inetprot.h:370
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:49
This is an array collection class of PString objects.
Definition: pstring.h:2024
virtual PBoolean WriteResponse(unsigned numericCode, const PString &info)
Write a response code followed by a text string describing the response to a command.
virtual int ExecuteCommand(PINDEX cmdNumber)
Write a command to the socket, using WriteCommand() and await a response using ReadResponse().
Definition: inetprot.h:370
PString defaultServiceName
Definition: inetprot.h:354
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:62
BOOL PBoolean
Definition: object.h:102
PBoolean newLineToCRLF
Definition: inetprot.h:374
void SetReadLineTimeout(const PTimeInterval &t)
Set the maximum timeout between characters within a line.
enum PInternetProtocol::StuffState stuffingState
PStringArray commandNames
Definition: inetprot.h:357
Definition: inetprot.h:370
virtual PBoolean WriteLine(const PString &line)
Write a string to the socket channel followed by a CR/LF pair.
The character string class.
Definition: pstring.h:108
virtual PBoolean Connect(const PString &address, WORD port=0)
Connect a socket to a remote host for the internet protocol.
Definition: inetprot.h:370
PString lastResponseInfo
Definition: inetprot.h:378
virtual void UnRead(int ch)
Put back the characters into the data stream so that the next Read() function call will return them f...
Definition: inetprot.h:370
PInternetProtocol(const char *defaultServiceName, PINDEX cmdCount, char const *const *cmdNames)
PIPSocket * GetSocket() const
Get the eventual socket for the series of indirect channels that may be between the current protocol ...
const PString & GetDefaultService() const
Get the default service name or port number to use in socket connections.
StuffState
Definition: inetprot.h:369
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
virtual PBoolean ReadResponse()
Read a response code followed by a text string describing the response to a command.
A network communications channel.
Definition: socket.h:58
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PTimeInterval readLineTimeout
Definition: inetprot.h:366
virtual PBoolean ReadLine(PString &line, PBoolean allowContinuation=false)
Read a string from the socket channel up to a CR/LF pair.
virtual PINDEX ParseResponse(const PString &line)
Parse a response line string into a response code and any extra info on the line. ...
virtual PBoolean Accept(PSocket &listener)
Accept a server socket to a remote host for the internet protocol.