PTLib Version 2.12.9

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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 * $Revision: 26195 $
27 * $Author: csoutheren $
28 * $Date: 2011-07-13 18:06:48 +1000 (Wed, 13 Jul 2011) $
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 #include <ptclib/mime.h>
40
41
42 class PSocket;
43 class PIPSocket;
44
45
65 class PInternetProtocol : public PIndirectChannel
66 {
67 PCLASSINFO(PInternetProtocol, PIndirectChannel)
68
69 protected:
70 PInternetProtocol(
71 const char * defaultServiceName,
72 PINDEX cmdCount,
73 char const * const * cmdNames
74 );
75 // Create an unopened TCP/IP protocol socket channel.
76
77
78 public:
79 // Overrides from class PChannel.
91 virtual PBoolean Read(
92 void * buf,
93 PINDEX len
94 );
95
103 virtual int ReadChar();
104
120 virtual PBoolean Write(
121 const void * buf,
122 PINDEX len
123 );
124
128 void SetReadLineTimeout(
129 const PTimeInterval & t
130 );
131
132 // New functions for class.
138 virtual PBoolean Connect(
139 const PString & address,
140 WORD port = 0
141 );
142 virtual PBoolean Connect(
143 const PString & address,
144 const PString & service
145 );
146
152 virtual PBoolean Accept(
153 PSocket & listener
154 );
155
162 const PString & GetDefaultService() const;
163
172 PIPSocket * GetSocket() const;
173
181 virtual PBoolean WriteLine(
182 const PString & line
183 );
184
201 virtual PBoolean ReadLine(
202 PString & line,
203 PBoolean allowContinuation = false
204 );
205
209 virtual void UnRead(
210 int ch
211 );
212 virtual void UnRead(
213 const PString & str
214 );
215 virtual void UnRead(
216 const void * buffer,
217 PINDEX len
218 );
219
233 virtual bool WriteCommand(
234 PINDEX cmdNumber,
235 const PString & param = PString::Empty()
236 );
237 virtual bool WriteCommand(
238 PINDEX cmdNumber,
239 const PString & param,
240 const PMIMEInfo & mime
241 );
242
260 virtual PBoolean ReadCommand(
261 PINDEX & num,
263 PString & args
264 );
265 virtual PBoolean ReadCommand(
266 PINDEX & num,
268 PString & args,
269 PMIMEInfo & mime
270 );
271
288 virtual PBoolean WriteResponse(
289 unsigned numericCode,
290 const PString & info
291 );
292 virtual PBoolean WriteResponse(
293 const PString & code,
294 const PString & info
295 );
296
315 virtual PBoolean ReadResponse();
316 virtual PBoolean ReadResponse(
317 int & code,
318 PString & info
319 );
320 virtual PBoolean ReadResponse(
321 int & code,
322 PString & info,
323 PMIMEInfo & mime
324 );
325
337 virtual int ExecuteCommand(
338 PINDEX cmdNumber
339 );
340 virtual int ExecuteCommand(
341 PINDEX cmdNumber,
342 const PString & param
343 );
344
351 int GetLastResponseCode() const;
352
358 PString GetLastResponseInfo() const;
359
360
361 protected:
373 virtual PINDEX ParseResponse(
374 const PString & line
375 );
376
377
378 PString defaultServiceName;
379 // Default Service name to use for the internet protocol socket.
380
381 PStringArray commandNames;
382 // Names of each of the command codes.
383
384 PCharArray unReadBuffer;
385 // Buffer for characters put back into the data stream.
386
387 PINDEX unReadCount;
388 // Buffer count for characters put back into the data stream.
389
390 PTimeInterval readLineTimeout;
391 // Time for characters in a line to be received.
392
393 enum StuffState {
394 DontStuff, StuffIdle, StuffCR, StuffCRLF, StuffCRLFdot, StuffCRLFdotCR
395 } stuffingState;
396 // Do byte stuffing of '.' characters in output to the socket channel.
397
398 PBoolean newLineToCRLF;
399 // Translate \\n characters to CR/LF pairs.
400
401 int lastResponseCode;
402 PString lastResponseInfo;
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 ///////////////////////////////////////////////////////////////