This sends a file assumed to be a whole HTML page. The HTML must not contain a server side include as there is no processing in this function to detect any such construct. The page may of course contain links to other resources as a means to complete rendering by the browser. Note this function does not use OpenInputStrm to open the file as it does not need the error code detail.

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

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

Function Logic:

0:START 1:unknown 2:items items 3:unknown 4:Z 5:Z 6:Pagename items 7:unknown 8:items 9:Return E_NOTFOUND 10:pEnd 11:unknown 12:type 13:type 14:items 15:unknown 16:items 17:Return E_OPENFAIL 18:Z items 19:unknown 20:items 21:Return E_NODATA 22:rc 23:unknown 24:items 25:Return E_WRITEFAIL 26:Return E_OK

Function body:

hzEcode hzHttpEvent::SendFilePage (const char* cpDir)const char* cpFilename, uint32_t nExpires, bool bZip, 
{
   //  This sends a file assumed to be a whole HTML page. The HTML must not contain a server side include as there is no processing in this function to detect
   //  any such construct. The page may of course contain links to other resources as a means to complete rendering by the browser.
   //  
   //  Arguments: 1) cpDir  The directory of the file (can be relative to current dir)
   //     2) cpFilename 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::SendFilePage") ;
   ifstream        is ;            //  Read file stream
   FSTAT           fs ;            //  File info
   hzChain         Z ;             //  Response for browser is built here
   const char*     pEnd ;          //  Filename extension and hence type
   hzString        Pagename ;      //  Full name (inc path) of page
   hzMimetype      type ;          //  File's HTTP type
   hzEcode         rc ;            //  Return code from sending function
   //  Formulate full path of page and then use lstat
   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 ;
   }
   //  Determine the type of file so that the correct header can be sent to the browser
   pEnd = strrchr(*Pagename, CHAR_PERIOD) ;
   if (!pEnd)
       type = HMTYPE_TXT_PLAIN ;
   else
       type = Filename2Mimetype(pEnd) ;
   //  Read in the file
   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 ;
   }
   //  If not a html file, no server side includes are possible so just send
   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 ;
}