| Return Type | Function name | Arguments |
|---|---|---|
| hzUrl& | hzUrl::operator= | (const char*,) |
Declared in file: hzUrl.h
Defined in file : hzUrl.cpp
Function Logic:
Function body:
hzUrl& hzUrl::operator= (const char* url)
{
_hzfunc("hzUrl::operator=") ;
_url_space* thisCtl ;
const char* pDom ;
const char* pRes ;
const char* _ptr ;
uint32_t lenProt = 0;
uint32_t lenDom = 0;
uint32_t lenPort = 0;
uint32_t lenRes = 0;
uint32_t lenTotal ;
uint32_t nPort = 80;
uint32_t nProto = 80;
uint32_t nAlphas = 0;
uint32_t nPeriod = 0;
uint32_t nWhite = 0;
bool bPort = false ;
Clear() ;
if (!url || !url[0])
return *this ;
for (_ptr = url ; *_ptr <&eq; CHAR_SPACE ; _ptr++) ;
/*
** ** Handle protocol component - Remove http:// or https:// to get to domain
** */
if (strstr(_ptr, "//"))
{
if (!memcmp(_ptr, "http://", 7)) { nProto = nPort = 80;lenProt = 7; }
else if (!memcmp(_ptr, "https://", 8)) { nProto = nPort = 443;lenProt= 8; }
else if (!memcmp(_ptr, "ws://", 5)) { nProto = nPort = 80;lenProt = 5; }
else if (!memcmp(_ptr, "wss://", 6)){ nProto = nPort = 443;lenProt= 6; }
else if (!memcmp(_ptr, "ftp://", 6)){ nProto = nPort = 21;lenProt = 6; }
else
{
hzerr(E_FORMAT, "Scheme not supported") ;
return *this ;
}
_ptr += lenProt ;
}
pDom = _ptr ;
/*
** ** Handle domain component: Read up to the end of the domain name. This could be the end of the test string or it
** ** could be a forward slash or a colon (for the port number)
** */
for (; *_ptr ; lenDom++, _ptr++)
{
if (*_ptr == CHAR_COLON) break ;
if (*_ptr == CHAR_FWSLASH) break ;
if (*_ptr == CHAR_PERIOD) { nPeriod++ ; continue ; }
if (*_ptr == CHAR_MINUS) { nAlphas++ ; continue ; }
if (*_ptr <&eq; CHAR_SPACE) { nWhite++ ; continue ; }
nAlphas++ ;
}
if (nWhite) { hzerr(E_FORMAT, "Has whitespace\n") ; return *this ; }
if (!nPeriod) { hzerr(E_FORMAT, "No periods\n") ; return *this ; }
if (!nAlphas) { hzerr(E_FORMAT, "No alphas\n") ; return *this ; }
/*
** ** Handle port component: Deal with case where domain string is terminated by a port indicator
** */
if (*_ptr == CHAR_COLON)
{
_ptr++ ;
for (nPort = 0,lenPort++ ; IsDigit(*_ptr) ; lenPort++)
{ nPort *= 10;nPort += (*_ptr - ''0'');_ptr++ ; }
if (nPort >&eq; 65536)
{
hzerr(E_FORMAT, "Bad port\n") ;
return *this ;
}
bPort = true ;
}
if (*_ptr >&eq; CHAR_SPACE && *_ptr != CHAR_FWSLASH)
return *this ;
/*
** ** Handle resource component: Read up to end of resource
** */
pRes = _ptr ;
for (; *_ptr > '' ''&&*_ptr != CHAR_QUERY ; lenRes++, _ptr++) ;
/*
** ** Compile finished URL
** */
lenTotal = lenProt + lenDom + lenPort + lenRes ;
m_addr = g_ssrInet.Alloc(lenTotal + URL_FACTOR) ;
thisCtl = (_url_space*) g_ssrInet.Xlate(m_addr) ;
thisCtl->m_copy = 1;
thisCtl->m_lenProt = lenProt ;
thisCtl->m_lenDom = lenDom ;
thisCtl->m_lenPort = lenPort ;
thisCtl->m_lenRes = lenRes ;
thisCtl->m_port = nPort ;
if (nProto == 80&&lenProt == 7)memcpy(thisCtl->m_data, "http://", lenProt) ;
else if (nProto == 443&&lenProt== 8)memcpy(thisCtl->m_data, "https://", lenProt) ;
else if (nProto == 80&&lenProt == 5)memcpy(thisCtl->m_data, "ws://", lenProt) ;
else if (nProto == 443&&lenProt== 6)memcpy(thisCtl->m_data, "wss://", lenProt) ;
else if (nProto == 21) memcpy(thisCtl->m_data, "ftp://", lenProt) ;
else
{
hzerr(E_FORMAT, "Bad scheme\n") ;
return *this ;
}
memcpy(thisCtl->m_data + lenProt, pDom, lenDom) ;
if (bPort)
sprintf(thisCtl->m_data + lenProt + lenDom, ":%d", nPort) ;
memcpy(thisCtl->m_data + lenProt + lenDom + lenPort, pRes, lenRes) ;
thisCtl->m_data[lenTotal] = 0;
return *this ;
}