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 _PINTERNETPROTOCOL
00032 #define _PINTERNETPROTOCOL
00033
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037
00038 #ifndef _PTLIB_H
00039 #include <ptlib.h>
00040 #endif
00041
00042 class PSocket;
00043 class PIPSocket;
00044
00045
00065 class PInternetProtocol : public PIndirectChannel
00066 {
00067 PCLASSINFO(PInternetProtocol, PIndirectChannel)
00068
00069 protected:
00070 PInternetProtocol(
00071 const char * defaultServiceName,
00072 PINDEX cmdCount,
00073 char const * const * cmdNames
00074 );
00075
00076
00077
00078 public:
00079
00091 virtual PBoolean Read(
00092 void * buf,
00093 PINDEX len
00094 );
00095
00111 virtual PBoolean Write(
00112 const void * buf,
00113 PINDEX len
00114 );
00115
00119 void SetReadLineTimeout(
00120 const PTimeInterval & t
00121 );
00122
00123
00129 virtual PBoolean Connect(
00130 const PString & address,
00131 WORD port = 0
00132 );
00133 virtual PBoolean Connect(
00134 const PString & address,
00135 const PString & service
00136 );
00137
00143 virtual PBoolean Accept(
00144 PSocket & listener
00145 );
00146
00153 const PString & GetDefaultService() const;
00154
00163 PIPSocket * GetSocket() const;
00164
00172 virtual PBoolean WriteLine(
00173 const PString & line
00174 );
00175
00192 virtual PBoolean ReadLine(
00193 PString & line,
00194 PBoolean allowContinuation = PFalse
00195 );
00196
00200 virtual void UnRead(
00201 int ch
00202 );
00203 virtual void UnRead(
00204 const PString & str
00205 );
00206 virtual void UnRead(
00207 const void * buffer,
00208 PINDEX len
00209 );
00210
00224 virtual PBoolean WriteCommand(
00225 PINDEX cmdNumber
00226 );
00227 virtual PBoolean WriteCommand(
00228 PINDEX cmdNumber,
00229 const PString & param
00230 );
00231
00249 virtual PBoolean ReadCommand(
00250 PINDEX & num,
00253 PString & args
00254 );
00255
00272 virtual PBoolean WriteResponse(
00273 unsigned numericCode,
00274 const PString & info
00275 );
00276 virtual PBoolean WriteResponse(
00277 const PString & code,
00278 const PString & info
00279 );
00280
00299 virtual PBoolean ReadResponse();
00300 virtual PBoolean ReadResponse(
00301 int & code,
00302 PString & info
00303 );
00304
00316 virtual int ExecuteCommand(
00317 PINDEX cmdNumber
00318 );
00319 virtual int ExecuteCommand(
00320 PINDEX cmdNumber,
00321 const PString & param
00322 );
00323
00330 int GetLastResponseCode() const;
00331
00337 PString GetLastResponseInfo() const;
00338
00339
00340 protected:
00352 virtual PINDEX ParseResponse(
00353 const PString & line
00354 );
00355
00356
00357 PString defaultServiceName;
00358
00359
00360 PStringArray commandNames;
00361
00362
00363 PCharArray unReadBuffer;
00364
00365
00366 PINDEX unReadCount;
00367
00368
00369 PTimeInterval readLineTimeout;
00370
00371
00372 enum StuffState {
00373 DontStuff, StuffIdle, StuffCR, StuffCRLF, StuffCRLFdot, StuffCRLFdotCR
00374 } stuffingState;
00375
00376
00377 PBoolean newLineToCRLF;
00378
00379
00380 int lastResponseCode;
00381 PString lastResponseInfo;
00382
00383
00384 private:
00385 PBoolean AttachSocket(PIPSocket * socket);
00386 };
00387
00388
00389
00390 #endif
00391
00392
00393