Purpose: Sends a HTML or other file to the browser but from memory. The first time the file is requested it is loaded into memory and then sent. On subsequent requests it is served from memory. Note this function does not use OpenInputStrm to open the file as it does not need the error code detail.

Return TypeFunction nameArguments
hzEcodehzHttpEvent::SendPageE(const char*,const char*,uint32_t,bool,)

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

Function Logic:

0:START 1:unknown 2:Return hzerr(E_ARGUMENT,No directory supplied) 3:unknown 4:Return hzerr(E_ARGUMENT,No filename supplied) 5:unknown 6:Filename 7:unknown 8:Filename 9:fname 10:Filename 11:Pagename Pagename Pagename 12:unknown 13:pChain 14:unknown 15:items 16:Return E_CORRUPT 17:unknown 18:items 19:Return E_NOTFOUND 20:unknown 21:items 22:Return E_NODATA 23:pChain items 24:unknown 25:Return hzerr(E_OPENFAIL,Could not open requested file (%s),*Pagename) 26:* items 27:unknown 28:Return hzerr(E_MEMORY,Could not load file (%s),*Pagename) 29:unknown 30:Return hzerr(E_MEMORY,Could not store file (%s),*Pagename) 31:pEnd 32:unknown 33:type 34:type 35:rc 36:unknown 37:Return hzerr(E_WRITEFAIL,Response data not sent to browser (size=%d, sock=%d),pChain->Size(),m_pCx->CliSocket()) 38:Return E_OK

Function body:

hzEcode hzHttpEvent::SendPageE (const char* dir)const char* fname, uint32_t nExpires, bool bZip, 
{
   //  Purpose: Sends a HTML or other file to the browser but from memory. The first time the file is requested it is loaded into
   //     memory and then sent. On subsequent requests it is served from memory.
   //  
   //  Arguments: 1) dir   The directory of the file (can be relative to current dir)
   //     2) fname  The file name.
   //     3) nExpires Expire time for page (for browser use only)
   //     4) bZip  Flag to indicate if the content is to be zipped
   //  
   //  Returns: E_NOTFOUND If the directory or filename cannot be accessed.
   //     E_OPENFAIL If the file could not be opened.
   //     E_NODATA If the file is empty.
   //     E_WRITEFAIL If the HTML data could not be sent to the browser.
   //     E_OK  If the operation was successful.
   //  
   //  Note this function does not use OpenInputStrm to open the file as it does not need the error code detail.
   _hzfunc("hzHttpEvent::SendPageE") ;
   hzChain*        pChain ;        //  Response for browser is built here
   const char*     pEnd ;          //  Filename extension and hence type
   hzString        Pagename ;      //  File to load
   hzString        Filename ;      //  File to load
   hzString        Content ;       //  Page content
   hzMimetype      type ;          //  File's HTTP type
   hzEcode         rc ;            //  Return code from sending function
   if (!dir || !dir[0])
       return hzerr(E_ARGUMENT, "No directory supplied") ;
   if (!fname || !fname[0])
       return hzerr(E_ARGUMENT, "No filename supplied") ;
   //  Lookup resource in page store
   //  Establish real filename, either fname or index.htm(l)
   if (fname[0]!= CHAR_FWSLASH)
       Filename = fname ;
   else
   {
       if (fname[1]== 0)
           Filename = "index.html" ;
       else
           Filename = fname + 1;
   }
   Pagename = dir ;
   Pagename += "/" ;
   Pagename += Filename ;
   if (s_PageStore.Exists(Pagename))
   {
       pChain = s_PageStore[Pagename] ;
       if (!pChain)
       {
           hzerr(E_CORRUPT, "Null entry in stored page for %s\n", *Pagename) ;
           return E_CORRUPT ;
       }
   }
   else
   {
       //  Check directory and filename of resource
       ifstream    is ;            //  Read file stream
       FSTAT       fs ;            //  File info
       if (stat(*Pagename, &fs) == -1)
       {
           //  return hzerr(E_NOTFOUND, "could not locate (%s)", *Pagename) ;
           SendError(HTTPMSG_NOTFOUND, "Could not locate %s\n", *Pagename) ;
           return E_NOTFOUND ;
       }
       if (fs.st_size == 0)
       {
           //  return hzerr(E_NODATA, "File (%s) of zero size!", *Pagename) ;
           SendError(HTTPMSG_NOTFOUND, "No content available for file %s\n", *Pagename) ;
           return E_NODATA ;
       }
       pChain = new hzChain() ;
       //  Read in the file
       is.open(*Pagename) ;
       if (is.fail())
           return hzerr(E_OPENFAIL, "Could not open requested file (%s)", *Pagename) ;
       *pChain += is ;
       is.close() ;
       if (pChain->Size() == 0)
           return hzerr(E_MEMORY, "Could not load file (%s)", *Pagename) ;
       //  Check chain has loaded
       if (s_PageStore.Insert(Pagename, pChain) != E_OK)
           return hzerr(E_MEMORY, "Could not store file (%s)", *Pagename) ;
   }
   //  Determine the type of file so that the correct header can be
   //  sent to the browser
   pEnd = strrchr(*Filename, CHAR_PERIOD) ;
   if (!pEnd)
       type = HMTYPE_TXT_PLAIN ;
   else
       type = Filename2Mimetype(pEnd) ;
   //  If not a html file, no server side includes are possible so just send
   rc = SendRawChain(HTTPMSG_OK, type, *pChain, nExpires, bZip) ;
   if (rc != E_OK)
       return hzerr(E_WRITEFAIL, "Response data not sent to browser (size=%d, sock=%d)", pChain->Size(), m_pCx->CliSocket()) ;
   return E_OK ;
}