Assign the URL by character string

Return TypeFunction nameArguments
hzUrl&hzUrl::operator=(const char*,)

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

Function Logic:

0:START 1:items 2:unknown 3:Return *this 4:unknown 5:unknown 6:unknown 7:nPort 8:nProto lenProt 9:!memcmp(_ptr,https://,8) 10:nPort 11:nProto lenProt 12:!memcmp(_ptr,ws://,5) 13:nPort 14:nProto lenProt 15:!memcmp(_ptr,wss://,6) 16:nPort 17:nProto lenProt 18:!memcmp(_ptr,ftp://,6) 19:nPort 20:nProto lenProt 21:items 22:Return *this 23:_ptr 24:pDom 25:unknown 26:unknown 27:unknown 28:unknown 29:items 30:unknown 31:items 32:unknown 33:items 34:items 35:unknown 36:items 37:Return *this 38:unknown 39:items 40:Return *this 41:unknown 42:items 43:Return *this 44:unknown 45:items 46:unknown 47:nPort * nPort items 48:unknown 49:items 50:Return *this 51:bPort 52:unknown 53:Return *this 54:pRes 55:unknown 56:lenPort 57:lenDom 58:lenProt 59:lenTotal m_addr thisCtl thisCtl thisCtl thisCtl thisCtl thisCtl thisCtl 60:unknown 61:items 62:nProto==443&&lenProt==8 63:items 64:nProto==80&&lenProt==5 65:items 66:nProto==443&&lenProt==6 67:items 68:nProto==21 69:items 70:items 71:Return *this 72:items 73:unknown 74:items 75:items thisCtl 76:Return *this

Function body:

hzUrl& hzUrl::operator= (const char* url)
{
   //  Assign the URL by character string
   //  
   //  Arguments: 1) url The whole URL as string
   //  
   //  Returns: Reference to this URL intance
   _hzfunc("hzUrl::operator=") ;
   _url_space* thisCtl ;           //  This URL space
   const char* pDom ;              //  Start of domain component
   const char* pRes ;              //  Start of resource component
   const char* _ptr ;              //  Char iterator
   uint32_t    lenProt = 0;        //  Length of protocol indicator (eg http://)
   uint32_t    lenDom = 0;     //  Length of domain name
   uint32_t    lenPort = 0;        //  Length of port indicator if present
   uint32_t    lenRes = 0;     //  Length of resource
   uint32_t    lenTotal ;          //  Length of whole string
   uint32_t    nPort = 80;     //  Port number
   uint32_t    nProto = 80;    //  Presumed port number of protocol
   uint32_t    nAlphas = 0;        //  Number of alphanum chars (must be at least one)
   uint32_t    nPeriod = 0;        //  Number of periods (must be at least one)
   uint32_t    nWhite = 0;     //  Number of whitespace chars
   bool        bPort = false ;     //  True only if a port component specified (:num)
   Clear() ;
   if (!url || !url[0])
       return *this ;
   //  threadLog("URL [%s]\n", url) ;
   //  Strip leading spaces to find real start
   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++ ;
   }
   //  Deal with failures
   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 ;
   }
   //  Should now have a terminator (<= space) or the / marking start of resource
   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 = _urlAlloc(lenTotal + URL_FACTOR) ;
   thisCtl = _urlXlate(m_addr) ;
   //  Do control part
   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
   //  Do protocol part
   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 ;
   }
   //  Do domain part
   memcpy(thisCtl->m_data + lenProt, pDom, lenDom) ;
   //  Do port part
   if (bPort)
       sprintf(thisCtl->m_data + lenProt + lenDom, ":%d", nPort) ;
   //  Do resource part
   memcpy(thisCtl->m_data + lenProt + lenDom + lenPort, pRes, lenRes) ;
   thisCtl->m_data[lenTotal] = 0;
   return *this ;
}