This is used as an alternative to the assignement operator, specifically to deal with such URLs as links in webpages. These may be full URLs with or without the scheme, but with the domain - or they can simply start with a / and consist only of the resource. Where the link lacks the domain, the supplied domain is used. Where the link does have a domain specified this takes precedence.
| Return Type | Function name | Arguments |
|---|---|---|
| hzUrl& | hzUrl::SetValue | (hzString,hzString,bool,uint32_t,) |
Declared in file: hzUrl.h
Defined in file : hzUrl.cpp
Function Logic:
Function body:
hzUrl& hzUrl::SetValue (hzString domain)hzString resource, bool bSecure, uint32_t nPort,
{
// This is used as an alternative to the assignement operator, specifically to deal with such URLs as links in webpages. These may be full URLs with or without the scheme, but
// with the domain - or they can simply start with a / and consist only of the resource. Where the link lacks the domain, the supplied domain is used. Where the link does have
// a domain specified this takes precedence.
//
// Arguments: 1) domain The domain name part of the URL
// 2) resource The resource part
// 3) bSecure Use SSL so https:// instead of http://
// 4) nPort Port number if any
//
// Returns: Reference to this URL intance
_url_space* thisCtl ; // This URL space
const char* pRI ; // Resource iterator
char* pTmp ; // Shuts compiler up about sprintf to buffer
hzString res ; // Resource (allowing a truncate after ?)
uint32_t lenTotal ; // Length of whole URL
uint32_t lenProt ; // Lenth of protocol part
uint32_t lenDom ; // Length of domain part
uint32_t lenRes ; // Length of resource part
uint32_t lenPort = 0; // Length of port part
bool bPort = false ; // Port specified indicator
/*
** ** Test arguments
** */
Clear() ;
if (!domain) return *this ;
if (!resource) return *this ;
res = resource ;
res.TruncateUpto("?") ;
if (memcmp(*res, "http://", 7)== 0)
{
operator=(res) ;
return *this ;
}
// If the port is not set it is determined by the protocol (http is 80 or https is 443).
if (!nPort)
nPort = bSecure ? 443:80;
else
{
// Don't include the :port_no notation unless we have a non-standard port
if (bSecure)
bPort = nPort == 443?false: true ;
else
bPort = nPort == 80?false : true ;
}
if (bPort)
lenPort = nPort > 9999?6:nPort> 999?5:nPort > 99?4: nPort > 9? 3: 2;
else
lenPort = 0;
lenProt = bSecure ? 8: 7;
lenDom = domain.Length() ;
pRI = *res ;
if (pRI[0]== CHAR_FWSLASH)
{
lenRes = res.Length() ;
pRI++ ;
}
else
lenRes = res.Length() + 1;
/*
** ** Compile finished URL
** */
lenTotal = lenProt + lenDom + lenPort + lenRes ;
m_addr = _urlAlloc(lenTotal + URL_FACTOR) ;
pTmp = (char*) _urlXlate(m_addr) ;
thisCtl = (_url_space*) pTmp ;
pTmp += 11;
// thisCtl = (_url_space*) _urlXlate(m_addr) ;
thisCtl->m_copy = 1; // No copies
thisCtl->m_lenProt = lenProt ; // Length of protocol component
thisCtl->m_lenDom = lenDom ; // Length of domain component
thisCtl->m_lenPort = lenPort ; // Length of port component
thisCtl->m_lenRes = lenRes ; // MSB of length of resource component
thisCtl->m_port = nPort ; // Port number
if (bSecure)
memcpy(thisCtl->m_data, "https://", lenProt) ;
else
memcpy(thisCtl->m_data, "http://", lenProt) ;
memcpy(thisCtl->m_data + lenProt, *domain, lenDom) ;
if (bPort)
{
pTmp += (lenProt + lenDom) ;
sprintf(pTmp, ":%d", nPort) ;
// sprintf(thisCtl->m_data + lenProt + lenDom, ":%d", nPort) ;
}
thisCtl->m_data[lenProt + lenDom + lenPort] = CHAR_FWSLASH ;
memcpy(thisCtl->m_data + lenProt + lenDom + lenPort + 1,pRI, lenRes - 1);
thisCtl->m_data[lenTotal] = 0;
return *this ;
}