Return TypeFunction nameArguments
hzEcodehzHttpEvent::SendFilePage(const char*,const char*,unsigned int,bool,)

Declared in file: hzHttpServer.h
Defined in file : hzHttpServer.cpp

Function Logic:

0:START 1:cpDir&&cpDir[0] 2:items hzChain::AddByte 3:!cpFilename||!cpFilename[0]||(cpFilename[0]==(char)47&&cpFilename[1]==0) 4:Z 5:Z 6:Pagename hzChain::Clear 7:lstat(*Pagename,&fs)==-1 8:hzHttpEvent::SendError 9:Return E_NOTFOUND 10:strrchr pEnd 11:!pEnd 12:type 13:Filename2Mimetype type 14:open ifstream::fail 15:is.fail() 16:hzHttpEvent::SendError 17:Return E_OPENFAIL 18:Z close hzChain::Size 19:!Z.Size() 20:hzHttpEvent::SendError 21:Return E_NODATA 22:hzHttpEvent::SendRawChain rc 23:rc!=E_OK 24:hzIpConnex::CliSocket 25:Return E_WRITEFAIL 26:Return E_OK

Function body:

hzEcode hzHttpEvent::SendFilePage (const char* cpDir, const char* cpFilename, unsigned int nExpires, bool bZip)
{
   _hzfunc("hzHttpEvent::SendFilePage") ;
   ifstream        is ;
   FSTAT           fs ;
   hzChain         Z ;
   const char*     pEnd ;
   hzString        Pagename ;
   hzMimetype      type ;
   hzEcode         rc ;
   if (cpDir && cpDir[0])
       { Z << cpDir ; Z.AddByte(CHAR_FWSLASH) ; }
   if (!cpFilename || !cpFilename[0]|| (cpFilename[0]== CHAR_FWSLASH && cpFilename[1]== 0))
       Z += "index.html" ;
   else
       Z += cpFilename ;
   Pagename = Z ;
   Z.Clear() ;
   if (lstat(*Pagename, &fs) == -1)
   {
       SendError(HTTPMSG_NOTFOUND, "Could not locate %s\n", *Pagename) ;
       return E_NOTFOUND ;
   }
   pEnd = strrchr(*Pagename, CHAR_PERIOD) ;
   if (!pEnd)
       type = HMTYPE_TXT_PLAIN ;
   else
       type = Filename2Mimetype(pEnd) ;
   is.open(*Pagename) ;
   if (is.fail())
   {
       SendError(HTTPMSG_NOTFOUND, "Could not open requested file (%s\n", *Pagename) ;
       return E_OPENFAIL ;
   }
   Z += is ;
   is.close() ;
   if (!Z.Size())
   {
       SendError(HTTPMSG_NOTFOUND, "File (%s) of zero size\n", *Pagename) ;
       return E_NODATA ;
   }
   rc = SendRawChain(HTTPMSG_OK, type, Z, nExpires, bZip) ;
   if (rc != E_OK)
   {
       hzerr(E_WRITEFAIL, "Response data not sent to browser (sock=%d)", m_pCx->CliSocket()) ;
       return E_WRITEFAIL ;
   }
   return E_OK ;
}