Execute the login process. This is always a case of downloading each page listed in m_Authspteps (if any) and then posting to the URL given in m_Authpage (if provided) with the name-value pairs listed in in m_Authform. Arguments: None

Return TypeFunction nameArguments
hzEcodehzWebhost::Login(void)

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

Function Logic:

0:START 1:items 2:unknown 3:items 4:Return E_OK 5:unknown 6:items 7:unknown 8:items 9:Return E_OK 10:unknown 11:url 12:unknown 13:bAuthpage 14:rc 15:unknown 16:rc items 17:unknown 18:Return rc 19:unknown 20:pDoc 21:unknown 22:items 23:Return E_NOTFOUND 24:unknown 25:unknown 26:m_Repos 27:S items 28:unknown 29:items 30:Return E_WRITEFAIL 31:items items items items items 32:rc 33:unknown 34:items 35:Return rc 36:unknown 37:m_Repos 38:S items 39:unknown 40:items 41:Return E_WRITEFAIL 42:items items items items 43:Return rc

Function body:

hzEcode hzWebhost::Login (void)
{
   //  Execute the login process. This is always a case of downloading each page listed in m_Authspteps (if any) and then posting to the URL given in m_Authpage (if provided) with
   //  the name-value pairs listed in in m_Authform.
   //  
   //  Arguments: None
   //  
   //  Returns: E_NOTFOUND If the login page was not located
   //     E_WRITEFAIL If the form recieved was not written to the repository
   //     E_OK  If the login form was posted (not the same thing as a successful login)
   _hzfunc("hzWebhost::Login") ;
   hzList<hzUrl>::Iter     ias ;       //  Iterator for URLs in m_Authsteps
   hzList<hzPair>::Iter    inv ;       //  Iterator for name-value pairs in m_Authform
   hzVect<hzString>        hdrs ;      //  Extra headers, needed for submit form (not generally applicable)
   ofstream    os ;                    //  For exporting to file
   hzDocument* pDoc ;                  //  Downoaded document
   hzPair      P ;                     //  Name-value pair instance
   hzUrl       url ;                   //  URL instance
   hzString    S ;                     //  Temp string
   hzString    etag ;                  //  For GetPage() call
   HttpRC      hRet ;                  //  HTML return code
   bool        bAuthpage = false ;     //  Set to true if the login form (if used) is correctly listed in m_Authsteps
   hzEcode     rc = E_OK ;             //  Return code
   threadLog("Starting Login Sequence\n") ;
   //  Werify we have to log on and if so, that the parameters are in place to support the login
   if (m_Opflags & HZ_WEBSYNC_AUTH_BASIC)
       { threadLog("Basis Authentication. No login process required\n") ; return E_OK ; }
   if (!(m_Opflags & (HZ_WEBSYNC_AUTH_POST | HZ_WEBSYNC_AUTH_GET)))
   {
       threadLog("No Authentication method\n") ;
       if (!m_Authsteps.Count() && !m_Authform.Count())
           { threadLog("No Authentication steps or form submission. No login process required\n") ; return E_OK ; }
   }
   //  Download all pages listed in m_Authsteps (note the download must happen even if the page is in the history because we need the cookies)
   for (ias = m_Authsteps ; rc == E_OK && ias.Valid() ; ias++)
   {
       url = ias.Element() ;
       if (url == m_Authpage)
           bAuthpage = true ;
       rc = HC.GetPage(hRet, url, etag) ;
       if (rc != E_OK)
           { rc = E_NOTFOUND ; threadLog("Could not download %s\n", *url) ; }
   }
   if (rc != E_OK)
       return rc ;
   if (!bAuthpage && m_Authpage)
   {
       pDoc = Download(m_Authpage) ;
       if (!pDoc)
           { threadLog("Could not download %s\n", *url) ; return E_NOTFOUND ; }
   }
   //  Now if there is a login form, post this now
   if (m_Authform.Count())
   {
       //  Write out login form to file
       if (m_Repos)
       {
           S = m_Repos + "/login_form" ;
           os.open(*S) ;
           if (os.fail())
               { threadLog("Cannot write out header file %s\n", *S) ; return E_WRITEFAIL ; }
           os << HC.m_Header ;
           os << "\r\n\r\n" ;
           os << HC.m_Content ;
           os.close() ;
           os.clear() ;
       }
       //  Post the form
       rc = HC.PostForm(hRet, m_Authpage, hdrs, m_Authform) ;
       if (rc != E_OK)
           { threadLog("Could not post form to %s\n", *m_Authpage) ; return rc ; }
       //  Write out the login response
       if (m_Repos)
       {
           S = m_Repos + "/login_response" ;
           os.open(*S) ;
           if (os.fail())
               { threadLog("Cannot write out header file %s\n", *S) ; return E_WRITEFAIL ; }
           os << HC.m_Header ;
           os << "\r\n\r\n" ;
           os << HC.m_Content ;
           os.close() ;
       }
   }
   return rc ;
}