SNAP Library 2.1, User Reference  2013-09-25 10:47:25
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

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


Constructor & Destructor Documentation

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

Definition at line 189 of file http.cpp.

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

Member Function Documentation

void THttpLx::ClrMemSf ( ) [inline]

Definition at line 203 of file http.cpp.

{SfMem.Clr();}
bool THttpLx::Eof ( ) [inline]

Definition at line 196 of file http.cpp.

{return AtEof;}
char THttpLx::GetCh ( )

Definition at line 239 of file http.cpp.

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

                     {
  if (Ch==TCh::CrCh){
    GetCh();
    if (Ch==TCh::LfCh){GetCh();} else {throw THttpEx(heCrLfExpected);}
  } else
  if (Ch==TCh::LfCh){
    GetCh();
  } else {
    throw THttpEx(heCrLfExpected);
  }
}

Definition at line 230 of file http.cpp.

                        {
  if (SIn->Eof()){
    if (AtEof){throw THttpEx(heUnexpectedEof);}
    AtEof=true; return 0;
  } else {
    Ch=SIn->GetCh(); return Ch;
  }
}

Definition at line 433 of file http.cpp.

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

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

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

{return SfMem;}
static TStr THttpLx::GetNrStr ( const TStr Str) [inline, static]

Definition at line 226 of file http.cpp.

{return ChDef.GetLcStr(Str);}

Definition at line 394 of file http.cpp.

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

Definition at line 315 of file http.cpp.

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

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

Definition at line 261 of file http.cpp.

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

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

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

Definition at line 273 of file http.cpp.

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

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

Definition at line 323 of file http.cpp.

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

Definition at line 371 of file http.cpp.

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

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

Definition at line 295 of file http.cpp.

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

{return EofChPrS.Len()+SIn->Len();}
THttpLx& THttpLx::operator= ( const THttpLx ) [inline]

Definition at line 193 of file http.cpp.

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

Definition at line 201 of file http.cpp.

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

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 [static, private]

Definition at line 181 of file http.cpp.

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: