PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
27 #ifndef PTLIB_INETPROT_H
28 #define PTLIB_INETPROT_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 
35 #include <ptclib/mime.h>
36 
37 
38 class PSocket;
39 class PIPSocket;
40 
41 
62 {
64 
65  protected:
67  const char * defaultServiceName,
68  PINDEX cmdCount,
69  char const * const * cmdNames
70  );
71  // Create an unopened TCP/IP protocol socket channel.
72 
73 
74  public:
75  // Overrides from class PChannel.
87  virtual PBoolean Read(
88  void * buf,
89  PINDEX len
90  );
91 
99  virtual int ReadChar();
100 
116  virtual PBoolean Write(
117  const void * buf,
118  PINDEX len
119  );
120 
124  void SetReadLineTimeout(
125  const PTimeInterval & t
126  );
127 
128  // New functions for class.
134  virtual PBoolean Connect(
135  const PString & address,
136  WORD port = 0
137  );
138  virtual PBoolean Connect(
139  const PString & address,
140  const PString & service
141  );
142 
148  virtual PBoolean Accept(
149  PSocket & listener
150  );
151 
158  const PString & GetDefaultService() const;
159 
168  PIPSocket * GetSocket() const;
169 
177  virtual PBoolean WriteLine(
178  const PString & line
179  );
180 
197  virtual PBoolean ReadLine(
198  PString & line,
199  PBoolean allowContinuation = false
200  );
201 
205  virtual void UnRead(
206  int ch
207  );
208  virtual void UnRead(
209  const PString & str
210  );
211  virtual void UnRead(
212  const void * buffer,
213  PINDEX len
214  );
215 
229  virtual bool WriteCommand(
230  PINDEX cmdNumber,
231  const PString & param = PString::Empty()
232  );
233  virtual bool WriteCommand(
234  PINDEX cmdNumber,
235  const PString & param,
236  const PMIMEInfo & mime
237  );
238 
256  virtual PBoolean ReadCommand(
257  PINDEX & num,
259  PString & args
260  );
261  virtual PBoolean ReadCommand(
262  PINDEX & num,
264  PString & args,
265  PMIMEInfo & mime
266  );
267 
284  virtual PBoolean WriteResponse(
285  unsigned numericCode,
286  const PString & info
287  );
288  virtual PBoolean WriteResponse(
289  const PString & code,
290  const PString & info
291  );
292 
311  virtual PBoolean ReadResponse();
312  virtual PBoolean ReadResponse(
313  int & code,
314  PString & info
315  );
316  virtual PBoolean ReadResponse(
317  int & code,
318  PString & info,
319  PMIMEInfo & mime
320  );
321 
333  virtual int ExecuteCommand(
334  PINDEX cmdNumber
335  );
336  virtual int ExecuteCommand(
337  PINDEX cmdNumber,
338  const PString & param
339  );
340 
348  { return m_lastResponseCode; }
349 
356  { return m_lastResponseInfo; }
357 
358 
359 
360  protected:
372  virtual PINDEX ParseResponse(
373  const PString & line
374  );
375 
376 
378  // Default Service name to use for the internet protocol socket.
379 
381  // Names of each of the command codes.
382 
384  // Buffer for characters put back into the data stream.
385 
386  PINDEX unReadCount;
387  // Buffer count for characters put back into the data stream.
388 
390  // Time for characters in a line to be received.
391 
392  enum StuffState {
394  } stuffingState;
395  // Do byte stuffing of '.' characters in output to the socket channel.
396 
398  // Translate \\n characters to CR/LF pairs.
399 
400  bool SetLastResponse(int code, const PString & info, ErrorGroup group = LastGeneralError);
403  // Responses
404 
405  private:
406  PBoolean AttachSocket(PIPSocket * socket);
407 };
408 
409 
410 
411 #endif // PTLIB_INETPROT_H
412 
413 
414 // End Of File ///////////////////////////////////////////////////////////////
virtual bool WriteCommand(PINDEX cmdNumber, const PString &param=PString::Empty())
Write a single line for a command.
This class contains the Multipurpose Internet Mail Extensions parameters and variables.
Definition: mime.h:48
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
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:552
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
int GetLastResponseCode() const
Return the code associated with the last response received by the socket.
Definition: inetprot.h:347
Error during other operation, eg Open()
Definition: channel.h:254
PString GetLastResponseInfo() const
Return the last response received by the socket.
Definition: inetprot.h:355
PCharArray unReadBuffer
Definition: inetprot.h:383
PINDEX unReadCount
Definition: inetprot.h:386
This class describes a type of socket that will communicate using the Internet Protocol.
Definition: ipsock.h:47
Definition: inetprot.h:393
Definition: inetprot.h:393
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:45
This is an array collection class of PString objects.
Definition: pstring.h:2365
bool SetLastResponse(int code, const PString &info, ErrorGroup group=LastGeneralError)
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:393
PString defaultServiceName
Definition: inetprot.h:377
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:61
PBoolean newLineToCRLF
Definition: inetprot.h:397
void SetReadLineTimeout(const PTimeInterval &t)
Set the maximum timeout between characters within a line.
enum PInternetProtocol::StuffState stuffingState
PStringArray commandNames
Definition: inetprot.h:380
PString m_lastResponseInfo
Definition: inetprot.h:402
bool PBoolean
Definition: object.h:174
Definition: inetprot.h:393
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
int m_lastResponseCode
Definition: inetprot.h:401
virtual PBoolean Connect(const PString &address, WORD port=0)
Connect a socket to a remote host for the internet protocol.
ErrorGroup
Error groups.
Definition: channel.h:251
Definition: inetprot.h:393
virtual int ReadChar()
Read a single 8 bit byte from the channel.
static const PString & Empty()
Return an empty string.
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:393
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:392
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:59
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PTimeInterval readLineTimeout
Definition: inetprot.h:389
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.