SNAP Library, Developer Reference
2012-10-15 15:06:59
SNAP, a general purpose network analysis and graph mining library
|
Public Member Functions | |
THttpLx (const PSIn &_SIn) | |
THttpLx & | operator= (const THttpLx &) |
bool | Eof () |
int | Len () |
char | GetFirstCh () |
char | GetCh () |
void | GetRest () |
void | PutCh (const char &_Ch) |
void | ClrMemSf () |
TMem & | GetMemSf () |
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 |
THttpLx::THttpLx | ( | const PSIn & | _SIn | ) | [inline] |
Definition at line 188 of file http.cpp.
References GetFirstCh().
void THttpLx::ClrMemSf | ( | ) | [inline] |
Definition at line 202 of file http.cpp.
References SfMem.
Referenced by ParseHttpResp(), and ParseHttpRq().
{SfMem.Clr();}
bool THttpLx::Eof | ( | ) | [inline] |
Definition at line 195 of file http.cpp.
References AtEof.
Referenced by GetFldVal(), GetRespReasonPhrase(), GetRqMethod(), GetToken(), GetUrl(), GetUrlStr(), GetWs(), ParseHttpResp(), and ParseHttpRq().
{return AtEof;}
char THttpLx::GetCh | ( | ) |
Definition at line 238 of file http.cpp.
References AtEof, Ch, TSStack< TVal >::Empty(), TSIn::Eof(), EofChPrS, TSIn::GetCh(), heUnexpectedEof, TCh::NullCh, TSStack< TVal >::Pop(), SfMem, SIn, TSStack< TVal >::Top(), TPair< TVal1, TVal2 >::Val1, and TPair< TVal1, TVal2 >::Val2.
Referenced by GetCrLf(), GetFldVal(), GetInt(), GetLws(), GetPeriod(), GetRespReasonPhrase(), GetRest(), GetRqMethod(), GetSpec(), GetToken(), GetUrl(), GetUrlStr(), GetWs(), IsCrLf(), IsLws(), and IsRespStatusLn().
{ if (EofChPrS.Empty()){ if (SIn->Eof()){ if (AtEof){throw THttpEx(heUnexpectedEof);} AtEof=true; SfMem+=Ch; Ch=TCh::NullCh; return Ch; } else { SfMem+=Ch; Ch=SIn->GetCh(); return Ch; } } else { SfMem+=Ch; AtEof=EofChPrS.Top().Val1; Ch=EofChPrS.Top().Val2; EofChPrS.Pop(); return Ch; } }
void THttpLx::GetCrLf | ( | ) |
Definition at line 381 of file http.cpp.
References Ch, TCh::CrCh, GetCh(), heCrLfExpected, and TCh::LfCh.
Referenced by ParseHttpResp(), and ParseHttpRq().
{ if (Ch==TCh::CrCh){ GetCh(); if (Ch==TCh::LfCh){GetCh();} else {throw THttpEx(heCrLfExpected);} } else if (Ch==TCh::LfCh){ GetCh(); } else { throw THttpEx(heCrLfExpected); } }
char THttpLx::GetFirstCh | ( | ) |
Definition at line 229 of file http.cpp.
References AtEof, Ch, TSIn::Eof(), TSIn::GetCh(), heUnexpectedEof, and SIn.
Referenced by THttpLx().
{ if (SIn->Eof()){ if (AtEof){throw THttpEx(heUnexpectedEof);} AtEof=true; return 0; } else { Ch=SIn->GetCh(); return Ch; } }
Definition at line 432 of file http.cpp.
References Ch, ChDef, TCh::CrCh, Eof(), GetCh(), GetLws(), IsLws(), THttpChDef::IsText(), and TCh::LfCh.
Referenced by ParseHttpResp(), and ParseHttpRq().
{ TChA FldValStr; do { GetLws(); while (!Eof()&&ChDef.IsText(Ch)&&(Ch!=TCh::CrCh)&&(Ch!=TCh::LfCh)){ FldValStr+=Ch; GetCh();} if (IsLws()){FldValStr+=' ';} } while (IsLws()); return FldValStr; }
int THttpLx::GetInt | ( | const int & | RqPlaces = -1 | ) |
Definition at line 421 of file http.cpp.
References Ch, ChDef, GetCh(), GetLws(), heInvalidNumPlaces, heNumExpected, and THttpChDef::IsDigit().
Referenced by ParseHttpResp(), and ParseHttpRq().
{ GetLws(); if (!ChDef.IsDigit(Ch)){throw THttpEx(heNumExpected);} int Int=0; int CurPlaces=0; do {Int=Int*10+Ch-'0'; CurPlaces++; GetCh(); } while ((CurPlaces<RqPlaces)&&(ChDef.IsDigit(Ch))); if (RqPlaces!=-1){ if (CurPlaces!=RqPlaces){throw THttpEx(heInvalidNumPlaces);}} return Int; }
void THttpLx::GetLws | ( | ) |
Definition at line 347 of file http.cpp.
References Ch, TCh::CrCh, forever, GetCh(), TCh::LfCh, PutCh(), and TCh::TabCh.
Referenced by GetFldVal(), GetInt(), GetRespReasonPhrase(), GetSpec(), and GetToken().
{ forever { while ((Ch==' ')||(Ch==TCh::TabCh)){GetCh();} if (Ch==TCh::CrCh){ GetCh(); if (Ch==TCh::LfCh){ GetCh(); if ((Ch==' ')||(Ch==TCh::TabCh)){GetCh();} else {PutCh(TCh::LfCh); PutCh(TCh::CrCh); break;} } else { PutCh(TCh::CrCh); break; } } else if (Ch==TCh::LfCh){ GetCh(); if ((Ch==' ')||(Ch==TCh::TabCh)){GetCh();} else {PutCh(TCh::LfCh); break;} } else { break; } } }
TMem& THttpLx::GetMemSf | ( | ) | [inline] |
Definition at line 203 of file http.cpp.
References SfMem.
Referenced by ParseHttpResp(), and ParseHttpRq().
{return SfMem;}
static TStr THttpLx::GetNrStr | ( | const TStr & | Str | ) | [inline, static] |
Definition at line 225 of file http.cpp.
References ChDef, and THttpChDef::GetLcStr().
Referenced by AddFldVal(), AddHdFld(), GetFldValV(), GetToken(), IsFldNm(), IsFldVal(), ParseHttpResp(), ParseHttpRq(), and THttpRq().
void THttpLx::GetPeriod | ( | ) |
Definition at line 393 of file http.cpp.
References Ch, GetCh(), GetWs(), and hePeriodExpected.
Referenced by ParseHttpResp(), and ParseHttpRq().
{ GetWs(); if (Ch!='.'){throw THttpEx(hePeriodExpected);} GetCh(); }
Definition at line 314 of file http.cpp.
References Ch, ChDef, TCh::CrCh, Eof(), GetCh(), GetLws(), THttpChDef::IsText(), and TCh::LfCh.
Referenced by ParseHttpResp().
{ GetLws(); TChA RPStr; while (!Eof()&&ChDef.IsText(Ch)&&(Ch!=TCh::CrCh)&&(Ch!=TCh::LfCh)){ RPStr+=Ch; GetCh();} return RPStr; }
void THttpLx::GetRest | ( | ) |
Definition at line 253 of file http.cpp.
References Ch, TSStack< TVal >::Empty(), TSIn::Eof(), EofChPrS, GetCh(), LoadMem(), SfMem, SIn, and TMem().
Referenced by ParseHttpResp(), and ParseHttpRq().
{ while ((!SIn->Eof())&&(!EofChPrS.Empty())){GetCh();} if (!SIn->Eof()){SfMem+=Ch;} TMem RestMem; TMem::LoadMem(SIn, RestMem); SfMem+=RestMem; }
Definition at line 260 of file http.cpp.
References Ch, ChDef, Eof(), GetCh(), heMethodNmExpected, hrmGet, hrmHead, hrmPost, hrmUndef, THttpChDef::IsAlpha(), and Method.
Referenced by ParseHttpRq().
{ TChA MethodNm; while (!Eof() && ChDef.IsAlpha(Ch)){ MethodNm+=Ch; GetCh();} THttpRqMethod Method=hrmUndef; if (MethodNm==THttp::GetMethodNm){Method=hrmGet;} else if (MethodNm==THttp::HeadMethodNm){Method=hrmHead;} else if (MethodNm==THttp::PostMethodNm){Method=hrmPost;} if (Method==hrmUndef){throw THttpEx(heMethodNmExpected);} return Method; }
TStr THttpLx::GetSpec | ( | const TStr & | ExpectStr = TStr() | ) |
Definition at line 412 of file http.cpp.
References Ch, ChDef, TStr::Empty(), GetCh(), GetLws(), heInvalidTSpec, heTSpecExpected, and THttpChDef::IsSpec().
Referenced by ParseHttpResp(), and ParseHttpRq().
{ GetLws(); if (!ChDef.IsSpec(Ch)){throw THttpEx(heTSpecExpected);} TStr SpecStr(Ch); GetCh(); if (!ExpectStr.Empty()){ if (ExpectStr!=SpecStr){throw THttpEx(heInvalidTSpec);}} return SpecStr; }
TStr THttpLx::GetToken | ( | const TStr & | ExpectStr = TStr() | ) |
Definition at line 399 of file http.cpp.
References Ch, ChDef, TChA::Empty(), TStr::Empty(), Eof(), GetCh(), GetLws(), GetNrStr(), heInvalidToken, heTokenExpected, THttpChDef::IsCtl(), and THttpChDef::IsSpec().
Referenced by ParseHttpResp(), and ParseHttpRq().
{ GetLws(); TChA TokenStr; while (!Eof() && !ChDef.IsCtl(Ch) && !ChDef.IsSpec(Ch)){ TokenStr+=Ch; GetCh();} if (TokenStr.Empty()){throw THttpEx(heTokenExpected);} if (!ExpectStr.Empty()){ if (GetNrStr(ExpectStr)!=GetNrStr(TokenStr)){ throw THttpEx(heInvalidToken);} } return TokenStr; }
PUrl THttpLx::GetUrl | ( | ) |
Definition at line 272 of file http.cpp.
References Ch, ChDef, TChA::Empty(), Eof(), GetCh(), heBadUrl, heUrlEmpty, THttpChDef::IsSp(), TUrl(), and Url.
{ TChA UrlChA; while ((!Eof())&&(!ChDef.IsSp(Ch))){ UrlChA+=Ch; GetCh();} if (UrlChA.Empty()){ throw THttpEx(heUrlEmpty);} static TStr LocalBaseUrlStr="http://localhost/"; PUrl Url=PUrl(new TUrl(UrlChA, LocalBaseUrlStr)); if (!Url->IsOk()){ throw THttpEx(heBadUrl);} return Url; }
Definition at line 285 of file http.cpp.
References Ch, ChDef, TChA::Empty(), Eof(), GetCh(), heUrlEmpty, and THttpChDef::IsSp().
Referenced by ParseHttpRq().
{ TChA UrlChA; while ((!Eof())&&(!ChDef.IsSp(Ch))){ UrlChA+=Ch; GetCh();} if (UrlChA.Empty()){ throw THttpEx(heUrlEmpty);} return UrlChA; }
void THttpLx::GetWs | ( | ) |
Definition at line 322 of file http.cpp.
References Ch, Eof(), GetCh(), and TCh::TabCh.
Referenced by GetPeriod(), and ParseHttpRq().
{ while (!Eof()&&((Ch==' ')||(Ch==TCh::TabCh))){GetCh();} }
bool THttpLx::IsCrLf | ( | ) |
Definition at line 370 of file http.cpp.
References Ch, TCh::CrCh, GetCh(), TCh::LfCh, and PutCh().
Referenced by ParseHttpResp(), and ParseHttpRq().
{ if (Ch==TCh::CrCh){ GetCh(); bool Ok=(Ch==TCh::LfCh); PutCh(TCh::CrCh); return Ok; } else if (Ch==TCh::LfCh){ return true; } else { return false; } }
bool THttpLx::IsLws | ( | ) |
Definition at line 326 of file http.cpp.
References Ch, TCh::CrCh, GetCh(), TCh::LfCh, PutCh(), and TCh::TabCh.
Referenced by GetFldVal().
{ if ((Ch==' ')||(Ch==TCh::TabCh)){ return true; } else if (Ch==TCh::CrCh){ GetCh(); if (Ch==TCh::LfCh){ GetCh(); bool Ok=(Ch==' ')||(Ch==TCh::TabCh); PutCh(TCh::LfCh); PutCh(TCh::CrCh); return Ok; } else { PutCh(TCh::CrCh); return false; } } else if (Ch==TCh::LfCh){ GetCh(); bool Ok=(Ch==' ')||(Ch==TCh::TabCh); PutCh(TCh::LfCh); return Ok; } else { return false; } }
bool THttpLx::IsRespStatusLn | ( | ) |
Definition at line 294 of file http.cpp.
References Ch, ChDef, GetCh(), THttpChDef::GetLcCh(), THttpChDef::IsDigit(), Len(), TChA::Len(), PutCh(), and TChA::PutCh().
Referenced by ParseHttpResp().
{ static const TChA MouldChA="http/N.N NNN "; TChA TestChA(MouldChA); int TestLen=TestChA.Len(); if (1+Len()<TestLen){return false;} TestChA.PutCh(0, ChDef.GetLcCh(Ch)); {for (int ChN=1; ChN<TestLen; ChN++){ TestChA.PutCh(ChN, ChDef.GetLcCh(GetCh()));}} {for (int ChN=1; ChN<TestLen; ChN++){ PutCh(TestChA[TestLen-ChN-1]);}} {for (int ChN=0; ChN<MouldChA.Len(); ChN++){ if (MouldChA[ChN]=='N'){ if (!ChDef.IsDigit(TestChA[ChN])){return false;} } else { if (MouldChA[ChN]!=TestChA[ChN]){return false;} } }} return true; }
int THttpLx::Len | ( | ) | [inline] |
Definition at line 196 of file http.cpp.
References EofChPrS, TSIn::Len(), TSStack< TVal >::Len(), and SIn.
Referenced by IsRespStatusLn().
void THttpLx::PutCh | ( | const char & | _Ch | ) | [inline] |
bool THttpLx::AtEof [private] |
char THttpLx::Ch [private] |
Definition at line 184 of file http.cpp.
Referenced by GetCh(), GetCrLf(), GetFirstCh(), GetFldVal(), GetInt(), GetLws(), GetPeriod(), GetRespReasonPhrase(), GetRest(), GetRqMethod(), GetSpec(), GetToken(), GetUrl(), GetUrlStr(), GetWs(), IsCrLf(), IsLws(), IsRespStatusLn(), and PutCh().
THttpChDef THttpLx::ChDef [static, private] |
Definition at line 180 of file http.cpp.
Referenced by GetFldVal(), GetInt(), GetNrStr(), GetRespReasonPhrase(), GetRqMethod(), GetSpec(), GetToken(), GetUrl(), GetUrlStr(), and IsRespStatusLn().
TBoolChS THttpLx::EofChPrS [private] |
TMem THttpLx::SfMem [private] |
Definition at line 186 of file http.cpp.
Referenced by ClrMemSf(), GetCh(), GetMemSf(), GetRest(), and PutCh().
PSIn THttpLx::SIn [private] |