Analysis of Windows core programming code based on Visual C ++ (55) using googleurl for convenient and secure URL Parsing

Source: Internet
Author: User

During Google search, Google often uses Google's security filter to filter network Trojans for security reasons, such

 

 

The following is a practical example. based on VC ++, googleurl can be used to conveniently and securely parse URLs.

# Include "stdafx. H "# include" googleurl \ SRC \ gurl. H "Void testurl (const char * lpszurl) {char szdomain [256]; char szurlpath [256]; szdomain [0] = 0; szurlpath [0] = 0; const char * szstart = NULL; const char * szpathstart = NULL; If (strnicmp (lpszurl, "http: //", 7) = 0) {// start with HTTP: szstart = lpszurl + 7;} else if (strnicmp (lpszurl, "https: //", 8) = 0) {// szstart = lpszurl + 8 at the beginning of HTTPS;} else {szstart = lpszurl;} szpath Start = strstr (szstart, "/"); If (szpathstart) {strcpy (szurlpath, szpathstart);} strncpy (szdomain, szstart, szpathstart-szstart ); szdomain [szpathstart-szstart] = 0; printf ("% s \ ndomain: % s \ npath: % s \ n", lpszurl, szdomain, szurlpath );} int _ tmain (INT argc, _ tchar * argv []) {STD: cout <STD: Endl <"testurl" <STD: Endl; testurl ("http://www.baidu.com/index.html"); // testurl ("http://www.ABCDEFGHIJKLMNOPQ ") Why? Zookeeper extends rstuvwxyzabcdefghijk Lmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh urlstd: cout <STD: Endl <"googleurl" <STD: Endl; gurl ("http: // User: 123456@foo.tengattack.com: 8080/index. PHP? Action = init "); STD: cout <" url: "<gurl <STD: Endl; // obtain the domain name \ host address STD: cout <"host ()->" <gurl. host () <STD: Endl; // obtain the port number if (gurl. has_port () STD: cout <"port ()->" <gurl. port () <STD: Endl; // obtain queryif (gurl. has_query () STD: cout <"query ()->" <gurl. query () <STD: Endl; // obtain the username and password if (gurl. has_username () STD: cout <"username ()->" <gurl. username () <STD: Endl; If (gurl. has_password () STD: cout <"password ()->" <gurl. password () <STD: Endl; // get the file name STD: cout <"extractfilename ()->" <gurl. extractfilename () <STD: Endl; // This is also the port number. The difference with port () is that even if no port is specified, the HTTP 80 port STD :: cout <"effectiveintport ()->" <gurl. inclutiveintport () <STD: Endl; // determines whether the domain name is an IP address STD: cout <"hostisipaddress ()->" <gurl. hostisipaddress () <STD: Endl; STD: cin. get (); Return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.