int gxsURL::ParseURL(const gxString &url, gxsURLInfo &u, int strict) // Extract the specified URL in the following format: // URL protocol://username:password@hostname:port/path/filename // Extracts the hostname terminated with `/' or `:'. // Extracts the port number terminated with `/', or chosen for the protocol. // The directory name equals everything after the hostname. // The URL information will be passed back in the "u" variable. // Returns false if any errors occur during the parsing // operation. { u.url = url; int rv = ParseProtocol(url, u.proto, u.proto_type); if(strict && !rv) return 0; gxString clean_url; ParseUserName(url, u.user, u.passwd, clean_url); if(!ParseHostName(clean_url, u.host)) return 0; if(!ParsePortNumber(clean_url, u.port)) GetPortNumber(clean_url, u.port); if(u.proto_type == gxs_ftp) ProcessFTPType(clean_url, u.ftp_type); ParseDirectory(clean_url, u.path, u.dir, u.file); ParseDynamicPage(u); return 1; // No errors reported }
void IRCArgumentParser::FillInfo() { // fill in info based on option _info.is_verbose = false; for (auto iarg = 1; iarg < _argc; iarg += 2) { const _TCHAR* content = nullptr; if (iarg + 1 < _argc) content = _argv[iarg + 1]; switch (_argv[iarg][1]) { case _T('h'): // host ip:port ParseHostName(content); break; case _T('u'): // username and nickname NameCopy(content, _info.username); NameCopy(content, _info.nickname); break; case _T('n'): // real name NameCopy(content, _info.realname); break; case _T('p'): // password NameCopy(content, _info.password); break; case _T('v'): // verbose iarg -= 1; _info.is_verbose = true; break; } } }
int gxsURL::ParsePortNumber(const gxString &url, int &port) { gxString sbuf; port = -1; if(!ParseHostName(url, sbuf, 0)) return 0; // Look for a port number and remove everything before it int offset = sbuf.Find(":"); if(offset == -1) return 0; // No port number was found sbuf.DeleteAt(0, offset+1); port = sbuf.Atoi(); if(!port) return 0; // The port number was not valid return 1; }
void CHostSet::LoadFromFile( const char* strFile ) { ifstream ifg(strFile); char buf[MAXLINE]; while( !ifg.eof() && !ifg.fail() ){ ifg>>buf; if( strncmp(buf, "//", 2)==0 )continue; ParseHostName( buf ); // hostent* phent = gethostbyname( buf ); // if( phent!=NULL ){ // IN_ADDR addr; // bcopy( phent->h_addr, &addr, sizeof(IN_ADDR) ); // Add( addr, true ); // } } }