SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
THttpLx Class Reference

Public Member Functions

 THttpLx (const PSIn &_SIn)
 
THttpLxoperator= (const THttpLx &)
 
bool Eof ()
 
int Len ()
 
char GetFirstCh ()
 
char GetCh ()
 
void GetRest ()
 
void PutCh (const char &_Ch)
 
void ClrMemSf ()
 
TMemGetMemSf ()
 
THttpRqMethod GetRqMethod ()
 
PUrl GetUrl ()
 
TStr GetUrlStr ()
 
bool IsRespStatusLn ()
 
TStr GetRespReasonPhrase ()
 
void GetWs ()
 
bool IsLws ()
 
void GetLws ()
 
bool IsCrLf ()
 
void GetCrLf ()
 
void GetPeriod ()
 
TStr GetToken (const TStr &ExpectStr=TStr())
 
TStr GetSpec (const TStr &ExpectStr=TStr())
 
int GetInt (const int &RqPlaces=-1)
 
TStr GetFldVal ()
 

Static Public Member Functions

static TStr GetNrStr (const TStr &Str)
 

Private Attributes

PSIn SIn
 
TBoolChS EofChPrS
 
char Ch
 
bool AtEof
 
TMem SfMem
 

Static Private Attributes

static THttpChDef ChDef
 

Detailed Description

Definition at line 179 of file http.cpp.

Constructor & Destructor Documentation

THttpLx::THttpLx ( const PSIn _SIn)
inline

Definition at line 189 of file http.cpp.

189  :
190  SIn(_SIn), EofChPrS(), Ch(' '), AtEof(false), SfMem(50000){
191  GetFirstCh();}
char GetFirstCh()
Definition: http.cpp:230
PSIn SIn
Definition: http.cpp:182
TBoolChS EofChPrS
Definition: http.cpp:184
char Ch
Definition: http.cpp:185
TMem SfMem
Definition: http.cpp:187
bool AtEof
Definition: http.cpp:186

Member Function Documentation

void THttpLx::ClrMemSf ( )
inline

Definition at line 203 of file http.cpp.

203 {SfMem.Clr();}
TMem SfMem
Definition: http.cpp:187
void Clr(const bool &DoDel=true)
Definition: dt.h:131
bool THttpLx::Eof ( )
inline

Definition at line 196 of file http.cpp.

196 {return AtEof;}
bool AtEof
Definition: http.cpp:186
char THttpLx::GetCh ( )

Definition at line 239 of file http.cpp.

239  {
240  if (EofChPrS.Empty()){
241  if (SIn->Eof()){
242  if (AtEof){throw THttpEx(heUnexpectedEof);}
243  AtEof=true; SfMem+=Ch; Ch=TCh::NullCh; return Ch;
244  } else {
245  SfMem+=Ch; Ch=SIn->GetCh(); return Ch;
246  }
247  } else {
248  SfMem+=Ch;
250  return Ch;
251  }
252 }
bool Empty()
Definition: ds.h:2525
PSIn SIn
Definition: http.cpp:182
TVal & Top()
Definition: ds.h:2529
static const char NullCh
Definition: dt.h:943
TBoolChS EofChPrS
Definition: http.cpp:184
char Ch
Definition: http.cpp:185
virtual bool Eof()=0
TMem SfMem
Definition: http.cpp:187
void Pop()
Definition: ds.h:2533
TVal1 Val1
Definition: ds.h:34
TVal2 Val2
Definition: ds.h:35
virtual char GetCh()=0
bool AtEof
Definition: http.cpp:186
void THttpLx::GetCrLf ( )

Definition at line 382 of file http.cpp.

382  {
383  if (Ch==TCh::CrCh){
384  GetCh();
385  if (Ch==TCh::LfCh){GetCh();} else {throw THttpEx(heCrLfExpected);}
386  } else
387  if (Ch==TCh::LfCh){
388  GetCh();
389  } else {
390  throw THttpEx(heCrLfExpected);
391  }
392 }
char GetCh()
Definition: http.cpp:239
char Ch
Definition: http.cpp:185
static const char LfCh
Definition: dt.h:945
static const char CrCh
Definition: dt.h:946
char THttpLx::GetFirstCh ( )

Definition at line 230 of file http.cpp.

230  {
231  if (SIn->Eof()){
232  if (AtEof){throw THttpEx(heUnexpectedEof);}
233  AtEof=true; return 0;
234  } else {
235  Ch=SIn->GetCh(); return Ch;
236  }
237 }
PSIn SIn
Definition: http.cpp:182
char Ch
Definition: http.cpp:185
virtual bool Eof()=0
virtual char GetCh()=0
bool AtEof
Definition: http.cpp:186
TStr THttpLx::GetFldVal ( )

Definition at line 433 of file http.cpp.

433  {
434  TChA FldValStr;
435  do {
436  GetLws();
437  while (!Eof()&&ChDef.IsText(Ch)&&(Ch!=TCh::CrCh)&&(Ch!=TCh::LfCh)){
438  FldValStr+=Ch; GetCh();}
439  if (IsLws()){FldValStr+=' ';}
440  } while (IsLws());
441  return FldValStr;
442 }
char GetCh()
Definition: http.cpp:239
bool IsText(const char &Ch)
Definition: http.cpp:112
static THttpChDef ChDef
Definition: http.cpp:181
char Ch
Definition: http.cpp:185
bool Eof()
Definition: http.cpp:196
static const char LfCh
Definition: dt.h:945
Definition: dt.h:201
void GetLws()
Definition: http.cpp:348
static const char CrCh
Definition: dt.h:946
bool IsLws()
Definition: http.cpp:327
int THttpLx::GetInt ( const int &  RqPlaces = -1)

Definition at line 422 of file http.cpp.

422  {
423  GetLws();
424  if (!ChDef.IsDigit(Ch)){throw THttpEx(heNumExpected);}
425  int Int=0; int CurPlaces=0;
426  do {Int=Int*10+Ch-'0'; CurPlaces++; GetCh();
427  } while ((CurPlaces<RqPlaces)&&(ChDef.IsDigit(Ch)));
428  if (RqPlaces!=-1){
429  if (CurPlaces!=RqPlaces){throw THttpEx(heInvalidNumPlaces);}}
430  return Int;
431 }
char GetCh()
Definition: http.cpp:239
bool IsDigit(const char &Ch)
Definition: http.cpp:108
static THttpChDef ChDef
Definition: http.cpp:181
char Ch
Definition: http.cpp:185
void GetLws()
Definition: http.cpp:348
void THttpLx::GetLws ( )

Definition at line 348 of file http.cpp.

348  {
349  forever {
350  while ((Ch==' ')||(Ch==TCh::TabCh)){GetCh();}
351  if (Ch==TCh::CrCh){
352  GetCh();
353  if (Ch==TCh::LfCh){
354  GetCh();
355  if ((Ch==' ')||(Ch==TCh::TabCh)){GetCh();}
356  else {PutCh(TCh::LfCh); PutCh(TCh::CrCh); break;}
357  } else {
358  PutCh(TCh::CrCh); break;
359  }
360  } else
361  if (Ch==TCh::LfCh){
362  GetCh();
363  if ((Ch==' ')||(Ch==TCh::TabCh)){GetCh();}
364  else {PutCh(TCh::LfCh); break;}
365  } else {
366  break;
367  }
368  }
369 }
char GetCh()
Definition: http.cpp:239
#define forever
Definition: bd.h:6
char Ch
Definition: http.cpp:185
static const char TabCh
Definition: dt.h:944
static const char LfCh
Definition: dt.h:945
static const char CrCh
Definition: dt.h:946
void PutCh(const char &_Ch)
Definition: http.cpp:201
TMem& THttpLx::GetMemSf ( )
inline

Definition at line 204 of file http.cpp.

204 {return SfMem;}
TMem SfMem
Definition: http.cpp:187
static TStr THttpLx::GetNrStr ( const TStr Str)
inlinestatic

Definition at line 226 of file http.cpp.

226 {return ChDef.GetLcStr(Str);}
static THttpChDef ChDef
Definition: http.cpp:181
TStr GetLcStr(const TStr &Str)
Definition: http.cpp:156
void THttpLx::GetPeriod ( )

Definition at line 394 of file http.cpp.

394  {
395  GetWs();
396  if (Ch!='.'){throw THttpEx(hePeriodExpected);}
397  GetCh();
398 }
char GetCh()
Definition: http.cpp:239
void GetWs()
Definition: http.cpp:323
char Ch
Definition: http.cpp:185
TStr THttpLx::GetRespReasonPhrase ( )

Definition at line 315 of file http.cpp.

315  {
316  GetLws();
317  TChA RPStr;
318  while (!Eof()&&ChDef.IsText(Ch)&&(Ch!=TCh::CrCh)&&(Ch!=TCh::LfCh)){
319  RPStr+=Ch; GetCh();}
320  return RPStr;
321 }
char GetCh()
Definition: http.cpp:239
bool IsText(const char &Ch)
Definition: http.cpp:112
static THttpChDef ChDef
Definition: http.cpp:181
char Ch
Definition: http.cpp:185
bool Eof()
Definition: http.cpp:196
static const char LfCh
Definition: dt.h:945
Definition: dt.h:201
void GetLws()
Definition: http.cpp:348
static const char CrCh
Definition: dt.h:946
void THttpLx::GetRest ( )

Definition at line 254 of file http.cpp.

254  {
255  while ((!SIn->Eof())&&(!EofChPrS.Empty())){GetCh();}
256  if (!SIn->Eof()){SfMem+=Ch;}
257  TMem RestMem; TMem::LoadMem(SIn, RestMem);
258  SfMem+=RestMem;
259 }
bool Empty()
Definition: ds.h:2525
char GetCh()
Definition: http.cpp:239
PSIn SIn
Definition: http.cpp:182
TBoolChS EofChPrS
Definition: http.cpp:184
Definition: dt.h:77
char Ch
Definition: http.cpp:185
virtual bool Eof()=0
TMem SfMem
Definition: http.cpp:187
static void LoadMem(const PSIn &SIn, TMem &Mem)
Definition: dt.h:149
THttpRqMethod THttpLx::GetRqMethod ( )

Definition at line 261 of file http.cpp.

261  {
262  TChA MethodNm;
263  while (!Eof() && ChDef.IsAlpha(Ch)){
264  MethodNm+=Ch; GetCh();}
265  THttpRqMethod Method=hrmUndef;
266  if (MethodNm==THttp::GetMethodNm){Method=hrmGet;}
267  else if (MethodNm==THttp::HeadMethodNm){Method=hrmHead;}
268  else if (MethodNm==THttp::PostMethodNm){Method=hrmPost;}
269  if (Method==hrmUndef){throw THttpEx(heMethodNmExpected);}
270  return Method;
271 }
char GetCh()
Definition: http.cpp:239
static const TStr GetMethodNm
Definition: http.h:56
Definition: http.h:65
THttpRqMethod
Definition: http.h:64
static THttpChDef ChDef
Definition: http.cpp:181
Definition: http.h:65
char Ch
Definition: http.cpp:185
static const TStr HeadMethodNm
Definition: http.h:57
static const TStr PostMethodNm
Definition: http.h:58
Definition: http.h:65
bool Eof()
Definition: http.cpp:196
Definition: http.h:65
bool IsAlpha(const char &Ch)
Definition: http.cpp:107
Definition: dt.h:201
TStr THttpLx::GetSpec ( const TStr ExpectStr = TStr())

Definition at line 413 of file http.cpp.

413  {
414  GetLws();
415  if (!ChDef.IsSpec(Ch)){throw THttpEx(heTSpecExpected);}
416  TStr SpecStr(Ch); GetCh();
417  if (!ExpectStr.Empty()){
418  if (ExpectStr!=SpecStr){throw THttpEx(heInvalidTSpec);}}
419  return SpecStr;
420 }
char GetCh()
Definition: http.cpp:239
static THttpChDef ChDef
Definition: http.cpp:181
char Ch
Definition: http.cpp:185
void GetLws()
Definition: http.cpp:348
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
bool IsSpec(const char &Ch)
Definition: http.cpp:113
TStr THttpLx::GetToken ( const TStr ExpectStr = TStr())

Definition at line 400 of file http.cpp.

400  {
401  GetLws();
402  TChA TokenStr;
403  while (!Eof() && !ChDef.IsCtl(Ch) && !ChDef.IsSpec(Ch)){
404  TokenStr+=Ch; GetCh();}
405  if (TokenStr.Empty()){throw THttpEx(heTokenExpected);}
406  if (!ExpectStr.Empty()){
407  if (GetNrStr(ExpectStr)!=GetNrStr(TokenStr)){
408  throw THttpEx(heInvalidToken);}
409  }
410  return TokenStr;
411 }
static TStr GetNrStr(const TStr &Str)
Definition: http.cpp:226
char GetCh()
Definition: http.cpp:239
bool Empty() const
Definition: dt.h:260
static THttpChDef ChDef
Definition: http.cpp:181
char Ch
Definition: http.cpp:185
bool Eof()
Definition: http.cpp:196
Definition: dt.h:201
void GetLws()
Definition: http.cpp:348
bool IsCtl(const char &Ch)
Definition: http.cpp:109
bool Empty() const
Definition: dt.h:488
bool IsSpec(const char &Ch)
Definition: http.cpp:113
PUrl THttpLx::GetUrl ( )

Definition at line 273 of file http.cpp.

273  {
274  TChA UrlChA;
275  while ((!Eof())&&(!ChDef.IsSp(Ch))){
276  UrlChA+=Ch; GetCh();}
277  if (UrlChA.Empty()){
278  throw THttpEx(heUrlEmpty);}
279  static TStr LocalBaseUrlStr="http://localhost/";
280  PUrl Url=PUrl(new TUrl(UrlChA, LocalBaseUrlStr));
281  if (!Url->IsOk()){
282  throw THttpEx(heBadUrl);}
283  return Url;
284 }
char GetCh()
Definition: http.cpp:239
Definition: url.h:7
bool Empty() const
Definition: dt.h:260
static THttpChDef ChDef
Definition: http.cpp:181
TPt< TUrl > PUrl
Definition: url.h:7
char Ch
Definition: http.cpp:185
bool IsSp(const char &Ch)
Definition: http.cpp:117
bool Eof()
Definition: http.cpp:196
Definition: dt.h:201
Definition: dt.h:412
Definition: bd.h:196
TStr THttpLx::GetUrlStr ( )

Definition at line 286 of file http.cpp.

286  {
287  TChA UrlChA;
288  while ((!Eof())&&(!ChDef.IsSp(Ch))){
289  UrlChA+=Ch; GetCh();}
290  if (UrlChA.Empty()){
291  throw THttpEx(heUrlEmpty);}
292  return UrlChA;
293 }
char GetCh()
Definition: http.cpp:239
bool Empty() const
Definition: dt.h:260
static THttpChDef ChDef
Definition: http.cpp:181
char Ch
Definition: http.cpp:185
bool IsSp(const char &Ch)
Definition: http.cpp:117
bool Eof()
Definition: http.cpp:196
Definition: dt.h:201
void THttpLx::GetWs ( )

Definition at line 323 of file http.cpp.

323  {
324  while (!Eof()&&((Ch==' ')||(Ch==TCh::TabCh))){GetCh();}
325 }
char GetCh()
Definition: http.cpp:239
char Ch
Definition: http.cpp:185
static const char TabCh
Definition: dt.h:944
bool Eof()
Definition: http.cpp:196
bool THttpLx::IsCrLf ( )

Definition at line 371 of file http.cpp.

371  {
372  if (Ch==TCh::CrCh){
373  GetCh(); bool Ok=(Ch==TCh::LfCh); PutCh(TCh::CrCh); return Ok;
374  } else
375  if (Ch==TCh::LfCh){
376  return true;
377  } else {
378  return false;
379  }
380 }
char GetCh()
Definition: http.cpp:239
char Ch
Definition: http.cpp:185
static const char LfCh
Definition: dt.h:945
static const char CrCh
Definition: dt.h:946
void PutCh(const char &_Ch)
Definition: http.cpp:201
bool THttpLx::IsLws ( )

Definition at line 327 of file http.cpp.

327  {
328  if ((Ch==' ')||(Ch==TCh::TabCh)){
329  return true;
330  } else
331  if (Ch==TCh::CrCh){
332  GetCh();
333  if (Ch==TCh::LfCh){
334  GetCh(); bool Ok=(Ch==' ')||(Ch==TCh::TabCh);
335  PutCh(TCh::LfCh); PutCh(TCh::CrCh); return Ok;
336  } else {
337  PutCh(TCh::CrCh); return false;
338  }
339  } else
340  if (Ch==TCh::LfCh){
341  GetCh(); bool Ok=(Ch==' ')||(Ch==TCh::TabCh);
342  PutCh(TCh::LfCh); return Ok;
343  } else {
344  return false;
345  }
346 }
char GetCh()
Definition: http.cpp:239
char Ch
Definition: http.cpp:185
static const char TabCh
Definition: dt.h:944
static const char LfCh
Definition: dt.h:945
static const char CrCh
Definition: dt.h:946
void PutCh(const char &_Ch)
Definition: http.cpp:201
bool THttpLx::IsRespStatusLn ( )

Definition at line 295 of file http.cpp.

295  {
296  static const TChA MouldChA="http/N.N NNN ";
297  TChA TestChA(MouldChA);
298  int TestLen=TestChA.Len();
299  if (1+Len()<TestLen){return false;}
300  TestChA.PutCh(0, ChDef.GetLcCh(Ch));
301  {for (int ChN=1; ChN<TestLen; ChN++){
302  TestChA.PutCh(ChN, ChDef.GetLcCh(GetCh()));}}
303  {for (int ChN=1; ChN<TestLen; ChN++){
304  PutCh(TestChA[TestLen-ChN-1]);}}
305  {for (int ChN=0; ChN<MouldChA.Len(); ChN++){
306  if (MouldChA[ChN]=='N'){
307  if (!ChDef.IsDigit(TestChA[ChN])){return false;}
308  } else {
309  if (MouldChA[ChN]!=TestChA[ChN]){return false;}
310  }
311  }}
312  return true;
313 }
char GetCh()
Definition: http.cpp:239
int Len()
Definition: http.cpp:197
bool IsDigit(const char &Ch)
Definition: http.cpp:108
int Len() const
Definition: dt.h:259
static THttpChDef ChDef
Definition: http.cpp:181
char Ch
Definition: http.cpp:185
Definition: dt.h:201
char GetLcCh(const char &Ch)
Definition: http.cpp:121
void PutCh(const char &_Ch)
Definition: http.cpp:201
int THttpLx::Len ( )
inline

Definition at line 197 of file http.cpp.

197 {return EofChPrS.Len()+SIn->Len();}
PSIn SIn
Definition: http.cpp:182
TBoolChS EofChPrS
Definition: http.cpp:184
int Len()
Definition: ds.h:2528
virtual int Len() const =0
THttpLx& THttpLx::operator= ( const THttpLx )
inline

Definition at line 193 of file http.cpp.

193 {Fail; return *this;}
#define Fail
Definition: bd.h:238
void THttpLx::PutCh ( const char &  _Ch)
inline

Definition at line 201 of file http.cpp.

201  {
202  EofChPrS.Push(TBoolChPr(AtEof, Ch)); Ch=_Ch; AtEof=false; SfMem.Pop();}
char Pop()
Definition: dt.h:139
TBoolChS EofChPrS
Definition: http.cpp:184
char Ch
Definition: http.cpp:185
TPair< TBool, TCh > TBoolChPr
Definition: ds.h:76
TMem SfMem
Definition: http.cpp:187
void Push()
Definition: ds.h:2531
bool AtEof
Definition: http.cpp:186

Member Data Documentation

bool THttpLx::AtEof
private

Definition at line 186 of file http.cpp.

char THttpLx::Ch
private

Definition at line 185 of file http.cpp.

THttpChDef THttpLx::ChDef
staticprivate

Definition at line 181 of file http.cpp.

TBoolChS THttpLx::EofChPrS
private

Definition at line 184 of file http.cpp.

TMem THttpLx::SfMem
private

Definition at line 187 of file http.cpp.

PSIn THttpLx::SIn
private

Definition at line 182 of file http.cpp.


The documentation for this class was generated from the following file: