SNAP Library , Developer Reference  2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
THttpLx Class Reference
Collaboration diagram for THttpLx:

List of all members.

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 178 of file http.cpp.


Constructor & Destructor Documentation

THttpLx::THttpLx ( const PSIn _SIn) [inline]

Definition at line 188 of file http.cpp.

References GetFirstCh().

                           :
    SIn(_SIn), EofChPrS(), Ch(' '), AtEof(false), SfMem(50000){
    GetFirstCh();}

Here is the call graph for this function:


Member Function Documentation

void THttpLx::ClrMemSf ( ) [inline]

Definition at line 202 of file http.cpp.

References TMem::Clr(), and SfMem.

Referenced by THttpResp::ParseHttpResp(), and THttpRq::ParseHttpRq().

{SfMem.Clr();}

Here is the call graph for this function:

Here is the caller graph for this function:

bool THttpLx::Eof ( ) [inline]

Definition at line 195 of file http.cpp.

References AtEof.

Referenced by GetFldVal(), GetRespReasonPhrase(), GetRqMethod(), GetToken(), GetUrl(), GetUrlStr(), GetWs(), THttpResp::ParseHttpResp(), and THttpRq::ParseHttpRq().

{return AtEof;}

Here is the caller graph for this function:

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;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void THttpLx::GetCrLf ( )

Definition at line 381 of file http.cpp.

References Ch, TCh::CrCh, GetCh(), heCrLfExpected, and TCh::LfCh.

Referenced by THttpResp::ParseHttpResp(), and THttpRq::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);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 432 of file http.cpp.

References Ch, ChDef, TCh::CrCh, Eof(), GetCh(), GetLws(), IsLws(), THttpChDef::IsText(), and TCh::LfCh.

Referenced by THttpResp::ParseHttpResp(), and THttpRq::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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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 THttpResp::ParseHttpResp(), and THttpRq::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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

TMem& THttpLx::GetMemSf ( ) [inline]

Definition at line 203 of file http.cpp.

References SfMem.

Referenced by THttpResp::ParseHttpResp(), and THttpRq::ParseHttpRq().

{return SfMem;}

Here is the caller graph for this function:

static TStr THttpLx::GetNrStr ( const TStr Str) [inline, static]

Definition at line 393 of file http.cpp.

References Ch, GetCh(), GetWs(), and hePeriodExpected.

Referenced by THttpResp::ParseHttpResp(), and THttpRq::ParseHttpRq().

                       {
  GetWs();
  if (Ch!='.'){throw THttpEx(hePeriodExpected);}
  GetCh();
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 314 of file http.cpp.

References Ch, ChDef, TCh::CrCh, Eof(), GetCh(), GetLws(), THttpChDef::IsText(), and TCh::LfCh.

Referenced by THttpResp::ParseHttpResp().

                                 {
  GetLws();
  TChA RPStr;
  while (!Eof()&&ChDef.IsText(Ch)&&(Ch!=TCh::CrCh)&&(Ch!=TCh::LfCh)){
    RPStr+=Ch; GetCh();}
  return RPStr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void THttpLx::GetRest ( )

Definition at line 253 of file http.cpp.

References Ch, TSStack< TVal >::Empty(), TSIn::Eof(), EofChPrS, GetCh(), TMem::LoadMem(), SfMem, and SIn.

Referenced by THttpResp::ParseHttpResp(), and THttpRq::ParseHttpRq().

                     {
  while ((!SIn->Eof())&&(!EofChPrS.Empty())){GetCh();}
  if (!SIn->Eof()){SfMem+=Ch;}
  TMem RestMem; TMem::LoadMem(SIn, RestMem);
  SfMem+=RestMem;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 260 of file http.cpp.

References Ch, ChDef, Eof(), GetCh(), heMethodNmExpected, hrmGet, hrmHead, hrmPost, hrmUndef, and THttpChDef::IsAlpha().

Referenced by THttpRq::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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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 THttpResp::ParseHttpResp(), and THttpRq::ParseHttpRq().

                                          {
  GetLws();
  if (!ChDef.IsSpec(Ch)){throw THttpEx(heTSpecExpected);}
  TStr SpecStr(Ch); GetCh();
  if (!ExpectStr.Empty()){
    if (ExpectStr!=SpecStr){throw THttpEx(heInvalidTSpec);}}
  return SpecStr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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 THttpResp::ParseHttpResp(), and THttpRq::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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 272 of file http.cpp.

References Ch, ChDef, TChA::Empty(), Eof(), GetCh(), heBadUrl, heUrlEmpty, TUrl::IsOk(), and THttpChDef::IsSp().

                    {
  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;
}

Here is the call graph for this function:

Definition at line 285 of file http.cpp.

References Ch, ChDef, TChA::Empty(), Eof(), GetCh(), heUrlEmpty, and THttpChDef::IsSp().

Referenced by THttpRq::ParseHttpRq().

                       {
  TChA UrlChA;
  while ((!Eof())&&(!ChDef.IsSp(Ch))){
    UrlChA+=Ch; GetCh();}
  if (UrlChA.Empty()){
    throw THttpEx(heUrlEmpty);}
  return UrlChA;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void THttpLx::GetWs ( )

Definition at line 322 of file http.cpp.

References Ch, Eof(), GetCh(), and TCh::TabCh.

Referenced by GetPeriod(), and THttpRq::ParseHttpRq().

                   {
  while (!Eof()&&((Ch==' ')||(Ch==TCh::TabCh))){GetCh();}
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool THttpLx::IsCrLf ( )

Definition at line 370 of file http.cpp.

References Ch, TCh::CrCh, GetCh(), TCh::LfCh, and PutCh().

Referenced by THttpResp::ParseHttpResp(), and THttpRq::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;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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 THttpResp::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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int THttpLx::Len ( ) [inline]

Definition at line 196 of file http.cpp.

References EofChPrS, TSIn::Len(), TSStack< TVal >::Len(), and SIn.

Referenced by IsRespStatusLn().

{return EofChPrS.Len()+SIn->Len();}

Here is the call graph for this function:

Here is the caller graph for this function:

THttpLx& THttpLx::operator= ( const THttpLx ) [inline]

Definition at line 192 of file http.cpp.

References Fail.

{Fail; return *this;}
void THttpLx::PutCh ( const char &  _Ch) [inline]

Definition at line 200 of file http.cpp.

References AtEof, Ch, EofChPrS, TMem::Pop(), TSStack< TVal >::Push(), and SfMem.

Referenced by GetLws(), IsCrLf(), IsLws(), and IsRespStatusLn().

                             {
    EofChPrS.Push(TBoolChPr(AtEof, Ch)); Ch=_Ch; AtEof=false; SfMem.Pop();}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

bool THttpLx::AtEof [private]

Definition at line 185 of file http.cpp.

Referenced by Eof(), GetCh(), GetFirstCh(), and PutCh().

Definition at line 183 of file http.cpp.

Referenced by GetCh(), GetRest(), Len(), and PutCh().

TMem THttpLx::SfMem [private]

Definition at line 186 of file http.cpp.

Referenced by ClrMemSf(), GetCh(), GetMemSf(), GetRest(), and PutCh().

PSIn THttpLx::SIn [private]

Definition at line 181 of file http.cpp.

Referenced by GetCh(), GetFirstCh(), GetRest(), and Len().


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