00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef PTLIB_INETPROT_H
00032 #define PTLIB_INETPROT_H
00033
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037
00038
00039 class PSocket;
00040 class PIPSocket;
00041
00042
00062 class PInternetProtocol : public PIndirectChannel
00063 {
00064 PCLASSINFO(PInternetProtocol, PIndirectChannel)
00065
00066 protected:
00067 PInternetProtocol(
00068 const char * defaultServiceName,
00069 PINDEX cmdCount,
00070 char const * const * cmdNames
00071 );
00072
00073
00074
00075 public:
00076
00088 virtual PBoolean Read(
00089 void * buf,
00090 PINDEX len
00091 );
00092
00108 virtual PBoolean Write(
00109 const void * buf,
00110 PINDEX len
00111 );
00112
00116 void SetReadLineTimeout(
00117 const PTimeInterval & t
00118 );
00119
00120
00126 virtual PBoolean Connect(
00127 const PString & address,
00128 WORD port = 0
00129 );
00130 virtual PBoolean Connect(
00131 const PString & address,
00132 const PString & service
00133 );
00134
00140 virtual PBoolean Accept(
00141 PSocket & listener
00142 );
00143
00150 const PString & GetDefaultService() const;
00151
00160 PIPSocket * GetSocket() const;
00161
00169 virtual PBoolean WriteLine(
00170 const PString & line
00171 );
00172
00189 virtual PBoolean ReadLine(
00190 PString & line,
00191 PBoolean allowContinuation = PFalse
00192 );
00193
00197 virtual void UnRead(
00198 int ch
00199 );
00200 virtual void UnRead(
00201 const PString & str
00202 );
00203 virtual void UnRead(
00204 const void * buffer,
00205 PINDEX len
00206 );
00207
00221 virtual PBoolean WriteCommand(
00222 PINDEX cmdNumber
00223 );
00224 virtual PBoolean WriteCommand(
00225 PINDEX cmdNumber,
00226 const PString & param
00227 );
00228
00246 virtual PBoolean ReadCommand(
00247 PINDEX & num,
00250 PString & args
00251 );
00252
00269 virtual PBoolean WriteResponse(
00270 unsigned numericCode,
00271 const PString & info
00272 );
00273 virtual PBoolean WriteResponse(
00274 const PString & code,
00275 const PString & info
00276 );
00277
00296 virtual PBoolean ReadResponse();
00297 virtual PBoolean ReadResponse(
00298 int & code,
00299 PString & info
00300 );
00301
00313 virtual int ExecuteCommand(
00314 PINDEX cmdNumber
00315 );
00316 virtual int ExecuteCommand(
00317 PINDEX cmdNumber,
00318 const PString & param
00319 );
00320
00327 int GetLastResponseCode() const;
00328
00334 PString GetLastResponseInfo() const;
00335
00336
00337 protected:
00349 virtual PINDEX ParseResponse(
00350 const PString & line
00351 );
00352
00353
00354 PString defaultServiceName;
00355
00356
00357 PStringArray commandNames;
00358
00359
00360 PCharArray unReadBuffer;
00361
00362
00363 PINDEX unReadCount;
00364
00365
00366 PTimeInterval readLineTimeout;
00367
00368
00369 enum StuffState {
00370 DontStuff, StuffIdle, StuffCR, StuffCRLF, StuffCRLFdot, StuffCRLFdotCR
00371 } stuffingState;
00372
00373
00374 PBoolean newLineToCRLF;
00375
00376
00377 int lastResponseCode;
00378 PString lastResponseInfo;
00379
00380
00381 private:
00382 PBoolean AttachSocket(PIPSocket * socket);
00383 };
00384
00385
00386
00387 #endif // PTLIB_INETPROT_H
00388
00389
00390