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 Type | Function name | Arguments |
|---|---|---|
| hzEcode | hzWebhost::Login | (void) |
Declared in file: hzHttpClient.h
Defined in file : hzHttpClient.cpp
Function Logic:
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 ;
}