inetprot.h
Go to the documentation of this file.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
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 #ifndef _PINTERNETPROTOCOL
00093 #define _PINTERNETPROTOCOL
00094
00095 #ifdef P_USE_PRAGMA
00096 #pragma interface
00097 #endif
00098
00099 #include <ptlib.h>
00100
00101 class PSocket;
00102 class PIPSocket;
00103
00104
00124 class PInternetProtocol : public PIndirectChannel
00125 {
00126 PCLASSINFO(PInternetProtocol, PIndirectChannel)
00127
00128 protected:
00129 PInternetProtocol(
00130 const char * defaultServiceName,
00131 PINDEX cmdCount,
00132 char const * const * cmdNames
00133 );
00134
00135
00136
00137 public:
00138
00150 virtual BOOL Read(
00151 void * buf,
00152 PINDEX len
00153 );
00154
00170 virtual BOOL Write(
00171 const void * buf,
00172 PINDEX len
00173 );
00174
00178 void SetReadLineTimeout(
00179 const PTimeInterval & t
00180 );
00181
00182
00188 virtual BOOL Connect(
00189 const PString & address,
00190 WORD port = 0
00191 );
00192 virtual BOOL Connect(
00193 const PString & address,
00194 const PString & service
00195 );
00196
00202 virtual BOOL Accept(
00203 PSocket & listener
00204 );
00205
00212 const PString & GetDefaultService() const;
00213
00222 PIPSocket * GetSocket() const;
00223
00231 virtual BOOL WriteLine(
00232 const PString & line
00233 );
00234
00251 virtual BOOL ReadLine(
00252 PString & line,
00253 BOOL allowContinuation = FALSE
00254 );
00255
00259 virtual void UnRead(
00260 int ch
00261 );
00262 virtual void UnRead(
00263 const PString & str
00264 );
00265 virtual void UnRead(
00266 const void * buffer,
00267 PINDEX len
00268 );
00269
00283 virtual BOOL WriteCommand(
00284 PINDEX cmdNumber
00285 );
00286 virtual BOOL WriteCommand(
00287 PINDEX cmdNumber,
00288 const PString & param
00289 );
00290
00308 virtual BOOL ReadCommand(
00309 PINDEX & num,
00312 PString & args
00313 );
00314
00331 virtual BOOL WriteResponse(
00332 unsigned numericCode,
00333 const PString & info
00334 );
00335 virtual BOOL WriteResponse(
00336 const PString & code,
00337 const PString & info
00338 );
00339
00358 virtual BOOL ReadResponse();
00359 virtual BOOL ReadResponse(
00360 int & code,
00361 PString & info
00362 );
00363
00375 virtual int ExecuteCommand(
00376 PINDEX cmdNumber
00377 );
00378 virtual int ExecuteCommand(
00379 PINDEX cmdNumber,
00380 const PString & param
00381 );
00382
00389 int GetLastResponseCode() const;
00390
00396 PString GetLastResponseInfo() const;
00397
00398
00399 protected:
00411 virtual PINDEX ParseResponse(
00412 const PString & line
00413 );
00414
00415
00416 PString defaultServiceName;
00417
00418
00419 PStringArray commandNames;
00420
00421
00422 PCharArray unReadBuffer;
00423
00424
00425 PINDEX unReadCount;
00426
00427
00428 PTimeInterval readLineTimeout;
00429
00430
00431 enum StuffState {
00432 DontStuff, StuffIdle, StuffCR, StuffCRLF, StuffCRLFdot, StuffCRLFdotCR
00433 } stuffingState;
00434
00435
00436 BOOL newLineToCRLF;
00437
00438
00439 int lastResponseCode;
00440 PString lastResponseInfo;
00441
00442
00443 private:
00444 BOOL AttachSocket(PIPSocket * socket);
00445 };
00446
00447
00448
00449 #endif
00450
00451
00452