While no assumptions can be made about incoming messages within the hzIpServer regime itself, for HTTP it is expedient to ensure that messages (HTTP requests), are complete before being passed to the applicable callback function (by default hdsApp::ProcHTTP). This is acheived by creating a hzHttpEvent instance for the connection and calling hzHttpEvent::ProcessEvent on the data recieved so far. If this sets a flag indicating the message does constitute a complete HTTP request, then the callback function is invoked. Notes: This function is itself a callback function that is called every time a packet arrives on a port deemed to be using the HTTP protocol. It is defined as static to prevent it being called directly by the application.

Return TypeFunction nameArguments
hzTcpCodeHandleHttpMsg(hzChain&,hzIpConnex*,)

Declared and defined in file: hzIpServer.cpp

Function Logic:

0:START 1:unknown 2:items 3:pE 4:unknown 5:pCx 6:unknown 7:items items 8:Return TCP_TERMINATE 9:unknown 10:pCx items 11:Return TCP_INCOMPLETE 12:unknown 13:fnOnHttpEvent tcp_rc 14:items 15:Return tcp_rc

Function body:

hzTcpCode HandleHttpMsg (hzChain& Input)hzIpConnex* pCx, 
{
   //  Category: Internet Server
   //  
   //  While no assumptions can be made about incoming messages within the hzIpServer regime itself, for HTTP it is expedient to ensure that messages (HTTP requests), are complete
   //  before being passed to the applicable callback function (by default hdsApp::ProcHTTP).
   //  
   //  This is acheived by creating a hzHttpEvent instance for the connection and calling hzHttpEvent::ProcessEvent on the data recieved so far. If this sets a flag indicating the
   //  message does constitute a complete HTTP request, then the callback function is invoked.
   //  
   //  Arguments: 1) Input The input chain (maintained by the hzIpServer instance)
   //     2) pCx  The TCP connection the message is being received on
   //  
   //  Returns: A hzTcpCode to indicate keep-alive or terminate.
   //  
   //  Notes:  This function is itself a callback function that is called every time a packet arrives on a port deemed to be using
   //     the HTTP protocol. It is defined as static to prevent it being called directly by the application.
   _hzfunc("HandleHttpMsg") ;
   hzTcpCode   (*fnOnHttpEvent)(hzHttpEvent*) ;    //  HTTP event handle
   hzHttpEvent*    pE ;        //  The HTTP event message
   hzTcpCode       tcp_rc ;    //  TCP return code
   if (!pCx->m_pEventHdl)
       hzexit(E_MEMORY, "Could not allocate a HTTP Event") ;
   pE = (hzHttpEvent*) pCx->m_pEventHdl ;
   //  Know message complete - don't keep the pointer
   if (pCx->MsgComplete())
       pCx->m_pEventHdl = 0;
   //  First process message to see if it is complete. This also populates the hzHttpEvent instance
   if (pE->ProcessEvent(Input) != E_OK)
   {
       pCx->GetLogger()->Log("Deleting failed HTTP event input\n") ;
       Input.Clear() ;
       return TCP_TERMINATE ;
   }
   if (!pE->MsgComplete())
   {
       //  Know message incomplete - set the pointer
       pCx->m_pEventHdl = pE ;
       pCx->ExpectSize(pE->ExpectSize()) ;
       return TCP_INCOMPLETE ;
   }
   //  Call the applcation's function
   if (pCx->m_appFn)
   {
       fnOnHttpEvent = (hzTcpCode(*)(hzHttpEvent*)) pCx->m_appFn ;
       tcp_rc = fnOnHttpEvent(pE) ;
   }
   Input.Clear() ;
   return tcp_rc ;
}