]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/url.cc
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 23 URL Parsing */
13 #include "HttpRequest.h"
15 #include "SquidConfig.h"
16 #include "SquidString.h"
19 static const char valid_hostname_chars_u
[] =
20 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
21 "abcdefghijklmnopqrstuvwxyz"
25 static const char valid_hostname_chars
[] =
26 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
27 "abcdefghijklmnopqrstuvwxyz"
35 static SBuf
star("*");
42 static SBuf
slash("/");
47 URL::host(const char *src
)
51 if (hostAddr_
.isAnyAddr()) {
52 xstrncpy(host_
, src
, sizeof(host_
));
53 hostIsNumeric_
= false;
55 hostAddr_
.toHostStr(host_
, sizeof(host_
));
56 debugs(23, 3, "given IP: " << hostAddr_
);
65 // RFC 3986 section 3.3 says path can be empty (path-abempty).
66 // RFC 7230 sections 2.7.3, 5.3.1, 5.7.2 - says path cannot be empty, default to "/"
67 // at least when sending and using. We must still accept path-abempty as input.
68 if (path_
.isEmpty() && (scheme_
== AnyP::PROTO_HTTP
|| scheme_
== AnyP::PROTO_HTTPS
))
77 debugs(23, 5, "urlInitialize: Initializing...");
78 /* this ensures that the number of protocol strings is the same as
79 * the enum slots allocated because the last enum is always 'MAX'.
81 assert(strcmp(AnyP::ProtocolType_str
[AnyP::PROTO_MAX
], "MAX") == 0);
83 * These test that our matchDomainName() function works the
84 * way we expect it to.
86 assert(0 == matchDomainName("foo.com", "foo.com"));
87 assert(0 == matchDomainName(".foo.com", "foo.com"));
88 assert(0 == matchDomainName("foo.com", ".foo.com"));
89 assert(0 == matchDomainName(".foo.com", ".foo.com"));
90 assert(0 == matchDomainName("x.foo.com", ".foo.com"));
91 assert(0 == matchDomainName("y.x.foo.com", ".foo.com"));
92 assert(0 != matchDomainName("x.foo.com", "foo.com"));
93 assert(0 != matchDomainName("foo.com", "x.foo.com"));
94 assert(0 != matchDomainName("bar.com", "foo.com"));
95 assert(0 != matchDomainName(".bar.com", "foo.com"));
96 assert(0 != matchDomainName(".bar.com", ".foo.com"));
97 assert(0 != matchDomainName("bar.com", ".foo.com"));
98 assert(0 < matchDomainName("zzz.com", "foo.com"));
99 assert(0 > matchDomainName("aaa.com", "foo.com"));
100 assert(0 == matchDomainName("FOO.com", "foo.COM"));
101 assert(0 < matchDomainName("bfoo.com", "afoo.com"));
102 assert(0 > matchDomainName("afoo.com", "bfoo.com"));
103 assert(0 < matchDomainName("x-foo.com", ".foo.com"));
105 assert(0 == matchDomainName(".foo.com", ".foo.com", mdnRejectSubsubDomains
));
106 assert(0 == matchDomainName("x.foo.com", ".foo.com", mdnRejectSubsubDomains
));
107 assert(0 != matchDomainName("y.x.foo.com", ".foo.com", mdnRejectSubsubDomains
));
108 assert(0 != matchDomainName(".x.foo.com", ".foo.com", mdnRejectSubsubDomains
));
110 assert(0 == matchDomainName("*.foo.com", "x.foo.com", mdnHonorWildcards
));
111 assert(0 == matchDomainName("*.foo.com", ".x.foo.com", mdnHonorWildcards
));
112 assert(0 == matchDomainName("*.foo.com", ".foo.com", mdnHonorWildcards
));
113 assert(0 != matchDomainName("*.foo.com", "foo.com", mdnHonorWildcards
));
119 * Parse the scheme name from string b, into protocol type.
120 * The string must be 0-terminated.
123 urlParseProtocol(const char *b
)
125 // make e point to the ':' character
126 const char *e
= b
+ strcspn(b
, ":");
129 /* test common stuff first */
131 if (strncasecmp(b
, "http", len
) == 0)
132 return AnyP::PROTO_HTTP
;
134 if (strncasecmp(b
, "ftp", len
) == 0)
135 return AnyP::PROTO_FTP
;
137 if (strncasecmp(b
, "https", len
) == 0)
138 return AnyP::PROTO_HTTPS
;
140 if (strncasecmp(b
, "file", len
) == 0)
141 return AnyP::PROTO_FTP
;
143 if (strncasecmp(b
, "coap", len
) == 0)
144 return AnyP::PROTO_COAP
;
146 if (strncasecmp(b
, "coaps", len
) == 0)
147 return AnyP::PROTO_COAPS
;
149 if (strncasecmp(b
, "gopher", len
) == 0)
150 return AnyP::PROTO_GOPHER
;
152 if (strncasecmp(b
, "wais", len
) == 0)
153 return AnyP::PROTO_WAIS
;
155 if (strncasecmp(b
, "cache_object", len
) == 0)
156 return AnyP::PROTO_CACHE_OBJECT
;
158 if (strncasecmp(b
, "urn", len
) == 0)
159 return AnyP::PROTO_URN
;
161 if (strncasecmp(b
, "whois", len
) == 0)
162 return AnyP::PROTO_WHOIS
;
165 return AnyP::PROTO_UNKNOWN
;
167 return AnyP::PROTO_NONE
;
173 * Stores parsed values in the `request` argument.
175 * This abuses HttpRequest as a way of representing the parsed url
176 * and its components.
177 * method is used to switch parsers and to init the HttpRequest.
178 * If method is Http::METHOD_CONNECT, then rather than a URL a hostname:port is
180 * The url is non const so that if its too long we can NULL-terminate it in place.
184 * This routine parses a URL. Its assumed that the URL is complete -
185 * ie, the end of the string is the end of the URL. Don't pass a partial
186 * URL here as this routine doesn't have any way of knowing whether
187 * its partial or not (ie, it handles the case of no trailing slash as
188 * being "end of host with implied path of /".
191 URL::parse(const HttpRequestMethod
& method
, const char *url
)
193 LOCAL_ARRAY(char, proto
, MAX_URL
);
194 LOCAL_ARRAY(char, login
, MAX_URL
);
195 LOCAL_ARRAY(char, foundHost
, MAX_URL
);
196 LOCAL_ARRAY(char, urlpath
, MAX_URL
);
200 AnyP::ProtocolType protocol
= AnyP::PROTO_NONE
;
205 proto
[0] = foundHost
[0] = urlpath
[0] = login
[0] = '\0';
207 if ((l
= strlen(url
)) + Config
.appendDomainLen
> (MAX_URL
- 1)) {
208 debugs(23, DBG_IMPORTANT
, MYNAME
<< "URL too large (" << l
<< " bytes)");
211 if (method
== Http::METHOD_CONNECT
) {
213 * RFC 7230 section 5.3.3: authority-form = authority
214 * "excluding any userinfo and its "@" delimiter"
216 * RFC 3986 section 3.2: authority = [ userinfo "@" ] host [ ":" port ]
218 * As an HTTP(S) proxy we assume HTTPS (443) if no port provided.
222 if (sscanf(url
, "[%[^]]]:%d", foundHost
, &foundPort
) < 1)
223 if (sscanf(url
, "%[^:]:%d", foundHost
, &foundPort
) < 1)
226 } else if ((method
== Http::METHOD_OPTIONS
|| method
== Http::METHOD_TRACE
) &&
227 URL::Asterisk().cmp(url
) == 0) {
228 parseFinish(AnyP::PROTO_HTTP
, nullptr, url
, foundHost
, SBuf(), 80 /* HTTP default port */);
230 } else if (strncmp(url
, "urn:", 4) == 0) {
231 debugs(23, 3, "Split URI '" << url
<< "' into proto='urn', path='" << (url
+4) << "'");
232 debugs(50, 5, "urn=" << (url
+4));
233 setScheme(AnyP::PROTO_URN
, nullptr);
240 /* Find first : - everything before is protocol */
241 for (i
= 0, dst
= proto
; i
< l
&& *src
!= ':'; ++i
, ++src
, ++dst
) {
249 if ((i
+3) > l
|| *src
!= ':' || *(src
+ 1) != '/' || *(src
+ 2) != '/')
254 /* Then everything until first /; thats host (and port; which we'll look for here later) */
255 // bug 1881: If we don't get a "/" then we imply it was there
256 // bug 3074: We could just be given a "?" or "#". These also imply "/"
257 // bug 3233: whitespace is also a hostname delimiter.
258 for (dst
= foundHost
; i
< l
&& *src
!= '/' && *src
!= '?' && *src
!= '#' && *src
!= '\0' && !xisspace(*src
); ++i
, ++src
, ++dst
) {
263 * We can't check for "i >= l" here because we could be at the end of the line
264 * and have a perfectly valid URL w/ no trailing '/'. In this case we assume we've
265 * been -given- a valid URL and the path is just '/'.
271 // bug 3074: received 'path' starting with '?', '#', or '\0' implies '/'
272 if (*src
== '?' || *src
== '#' || *src
== '\0') {
278 /* Then everything from / (inclusive) until \r\n or \0 - thats urlpath */
279 for (; i
< l
&& *src
!= '\r' && *src
!= '\n' && *src
!= '\0'; ++i
, ++src
, ++dst
) {
283 /* We -could- be at the end of the buffer here */
286 /* If the URL path is empty we set it to be "/" */
287 if (dst
== urlpath
) {
293 protocol
= urlParseProtocol(proto
);
294 foundPort
= AnyP::UriScheme(protocol
).defaultPort();
296 /* Is there any login information? (we should eventually parse it above) */
297 t
= strrchr(foundHost
, '@');
299 strncpy((char *) login
, (char *) foundHost
, sizeof(login
)-1);
300 login
[sizeof(login
)-1] = '\0';
301 t
= strrchr(login
, '@');
303 strncpy((char *) foundHost
, t
+ 1, sizeof(foundHost
)-1);
304 foundHost
[sizeof(foundHost
)-1] = '\0';
305 // Bug 4498: URL-unescape the login info after extraction
306 rfc1738_unescape(login
);
309 /* Is there any host information? (we should eventually parse it above) */
310 if (*foundHost
== '[') {
311 /* strip any IPA brackets. valid under IPv6. */
313 /* only for IPv6 sadly, pre-IPv6/URL code can't handle the clean result properly anyway. */
316 l
= strlen(foundHost
);
318 for (; i
< l
&& *src
!= ']' && *src
!= '\0'; ++i
, ++src
, ++dst
) {
322 /* we moved in-place, so truncate the actual hostname found */
326 /* skip ahead to either start of port, or original EOS */
327 while (*dst
!= '\0' && *dst
!= ':')
331 t
= strrchr(foundHost
, ':');
333 if (t
!= strchr(foundHost
,':') ) {
334 /* RFC 2732 states IPv6 "SHOULD" be bracketed. allowing for times when its not. */
335 /* RFC 3986 'update' simply modifies this to an "is" with no emphasis at all! */
336 /* therefore we MUST accept the case where they are not bracketed at all. */
341 // Bug 3183 sanity check: If scheme is present, host must be too.
342 if (protocol
!= AnyP::PROTO_NONE
&& foundHost
[0] == '\0') {
343 debugs(23, DBG_IMPORTANT
, "SECURITY ALERT: Missing hostname in URL '" << url
<< "'. see access.log for details.");
347 if (t
&& *t
== ':') {
354 for (t
= foundHost
; *t
; ++t
)
357 if (stringHasWhitespace(foundHost
)) {
358 if (URI_WHITESPACE_STRIP
== Config
.uri_whitespace
) {
371 debugs(23, 3, "Split URL '" << url
<< "' into proto='" << proto
<< "', host='" << foundHost
<< "', port='" << foundPort
<< "', path='" << urlpath
<< "'");
373 if (Config
.onoff
.check_hostnames
&&
374 strspn(foundHost
, Config
.onoff
.allow_underscore
? valid_hostname_chars_u
: valid_hostname_chars
) != strlen(foundHost
)) {
375 debugs(23, DBG_IMPORTANT
, MYNAME
<< "Illegal character in hostname '" << foundHost
<< "'");
379 /* For IPV6 addresses also check for a colon */
380 if (Config
.appendDomain
&& !strchr(foundHost
, '.') && !strchr(foundHost
, ':'))
381 strncat(foundHost
, Config
.appendDomain
, SQUIDHOSTNAMELEN
- strlen(foundHost
) - 1);
383 /* remove trailing dots from hostnames */
384 while ((l
= strlen(foundHost
)) > 0 && foundHost
[--l
] == '.')
387 /* reject duplicate or leading dots */
388 if (strstr(foundHost
, "..") || *foundHost
== '.') {
389 debugs(23, DBG_IMPORTANT
, MYNAME
<< "Illegal hostname '" << foundHost
<< "'");
393 if (foundPort
< 1 || foundPort
> 65535) {
394 debugs(23, 3, "Invalid port '" << foundPort
<< "'");
398 #if HARDCODE_DENY_PORTS
399 /* These ports are filtered in the default squid.conf, but
400 * maybe someone wants them hardcoded... */
401 if (foundPort
== 7 || foundPort
== 9 || foundPort
== 19) {
402 debugs(23, DBG_CRITICAL
, MYNAME
<< "Deny access to port " << foundPort
);
407 if (stringHasWhitespace(urlpath
)) {
408 debugs(23, 2, "URI has whitespace: {" << url
<< "}");
410 switch (Config
.uri_whitespace
) {
412 case URI_WHITESPACE_DENY
:
415 case URI_WHITESPACE_ALLOW
:
418 case URI_WHITESPACE_ENCODE
:
419 t
= rfc1738_escape_unescaped(urlpath
);
420 xstrncpy(urlpath
, t
, MAX_URL
);
423 case URI_WHITESPACE_CHOP
:
424 *(urlpath
+ strcspn(urlpath
, w_space
)) = '\0';
427 case URI_WHITESPACE_STRIP
:
441 parseFinish(protocol
, proto
, urlpath
, foundHost
, SBuf(login
), foundPort
);
445 /// Update the URL object with parsed URI data.
447 URL::parseFinish(const AnyP::ProtocolType protocol
,
448 const char *const protoStr
, // for unknown protocols
449 const char *const aUrlPath
,
450 const char *const aHost
,
454 setScheme(protocol
, protoStr
);
465 authorityHttp_
.clear();
466 authorityWithPort_
.clear();
470 URL::authority(bool requirePort
) const
472 if (authorityHttp_
.isEmpty()) {
474 // both formats contain Host/IP
475 authorityWithPort_
.append(host());
476 authorityHttp_
= authorityWithPort_
;
478 // authorityForm_ only has :port if it is non-default
479 authorityWithPort_
.appendf(":%u",port());
480 if (port() != getScheme().defaultPort())
481 authorityHttp_
= authorityWithPort_
;
484 return requirePort
? authorityWithPort_
: authorityHttp_
;
488 URL::absolute() const
490 if (absolute_
.isEmpty()) {
491 // TODO: most URL will be much shorter, avoid allocating this much
492 absolute_
.reserveCapacity(MAX_URL
);
494 absolute_
.append(getScheme().image());
495 absolute_
.append(":",1);
496 if (getScheme() != AnyP::PROTO_URN
) {
497 absolute_
.append("//", 2);
498 const bool omitUserInfo
= getScheme() == AnyP::PROTO_HTTP
||
499 getScheme() != AnyP::PROTO_HTTPS
||
500 userInfo().isEmpty();
502 absolute_
.append(userInfo());
503 absolute_
.append("@", 1);
505 absolute_
.append(authority());
507 absolute_
.append(path());
513 /** \todo AYJ: Performance: This is an *almost* duplicate of HttpRequest::effectiveRequestUri(). But elides the query-string.
514 * After copying it on in the first place! Would be less code to merge the two with a flag parameter.
515 * and never copy the query-string part in the first place
518 urlCanonicalClean(const HttpRequest
* request
)
520 LOCAL_ARRAY(char, buf
, MAX_URL
);
522 snprintf(buf
, sizeof(buf
), SQUIDSBUFPH
, SQUIDSBUFPRINT(request
->effectiveRequestUri()));
523 buf
[sizeof(buf
)-1] = '\0';
525 // URN, CONNECT method, and non-stripped URIs can go straight out
526 if (Config
.onoff
.strip_query_terms
&& !(request
->method
== Http::METHOD_CONNECT
|| request
->url
.getScheme() == AnyP::PROTO_URN
)) {
527 // strip anything AFTER a question-mark
528 // leaving the '?' in place
529 if (auto t
= strchr(buf
, '?')) {
534 if (stringHasCntl(buf
))
535 xstrncpy(buf
, rfc1738_escape_unescaped(buf
), MAX_URL
);
541 * Yet another alternative to urlCanonical.
542 * This one adds the https:// parts to Http::METHOD_CONNECT URL
543 * for use in error page outputs.
544 * Luckily we can leverage the others instead of duplicating.
547 urlCanonicalFakeHttps(const HttpRequest
* request
)
549 LOCAL_ARRAY(char, buf
, MAX_URL
);
551 // method CONNECT and port HTTPS
552 if (request
->method
== Http::METHOD_CONNECT
&& request
->url
.port() == 443) {
553 snprintf(buf
, MAX_URL
, "https://%s/*", request
->url
.host());
557 // else do the normal complete canonical thing.
558 return urlCanonicalClean(request
);
562 * Test if a URL is relative.
564 * RFC 2396, Section 5 (Page 17) implies that in a relative URL, a '/' will
565 * appear before a ':'.
568 urlIsRelative(const char *url
)
579 for (p
= url
; *p
!= '\0' && *p
!= ':' && *p
!= '/'; ++p
);
588 * Convert a relative URL to an absolute URL using the context of a given
591 * It is assumed that you have already ensured that the URL is relative.
593 * If NULL is returned it is an indication that the method in use in the
594 * request does not distinguish between relative and absolute and you should
595 * use the url unchanged.
597 * If non-NULL is returned, it is up to the caller to free the resulting
598 * memory using safe_free().
601 urlMakeAbsolute(const HttpRequest
* req
, const char *relUrl
)
604 if (req
->method
.id() == Http::METHOD_CONNECT
) {
608 char *urlbuf
= (char *)xmalloc(MAX_URL
* sizeof(char));
610 if (req
->url
.getScheme() == AnyP::PROTO_URN
) {
611 // XXX: this is what the original code did, but it seems to break the
612 // intended behaviour of this function. It returns the stored URN path,
613 // not converting the given one into a URN...
614 snprintf(urlbuf
, MAX_URL
, SQUIDSBUFPH
, SQUIDSBUFPRINT(req
->url
.absolute()));
618 SBuf authorityForm
= req
->url
.authority(); // host[:port]
619 const SBuf
&scheme
= req
->url
.getScheme().image();
620 size_t urllen
= snprintf(urlbuf
, MAX_URL
, SQUIDSBUFPH
"://" SQUIDSBUFPH
"%s" SQUIDSBUFPH
,
621 SQUIDSBUFPRINT(scheme
),
622 SQUIDSBUFPRINT(req
->url
.userInfo()),
623 !req
->url
.userInfo().isEmpty() ? "@" : "",
624 SQUIDSBUFPRINT(authorityForm
));
626 // if the first char is '/' assume its a relative path
627 // XXX: this breaks on scheme-relative URLs,
628 // but we should not see those outside ESI, and rarely there.
629 // XXX: also breaks on any URL containing a '/' in the query-string portion
630 if (relUrl
[0] == '/') {
631 xstrncpy(&urlbuf
[urllen
], relUrl
, MAX_URL
- urllen
- 1);
633 SBuf path
= req
->url
.path();
634 SBuf::size_type lastSlashPos
= path
.rfind('/');
636 if (lastSlashPos
== SBuf::npos
) {
637 // replace the whole path with the given bit(s)
638 urlbuf
[urllen
] = '/';
640 xstrncpy(&urlbuf
[urllen
], relUrl
, MAX_URL
- urllen
- 1);
642 // replace only the last (file?) segment with the given bit(s)
644 if (lastSlashPos
> MAX_URL
- urllen
- 1) {
645 // XXX: crops bits in the middle of the combined URL.
646 lastSlashPos
= MAX_URL
- urllen
- 1;
648 SBufToCstring(&urlbuf
[urllen
], path
.substr(0,lastSlashPos
));
649 urllen
+= lastSlashPos
;
650 if (urllen
+ 1 < MAX_URL
) {
651 xstrncpy(&urlbuf
[urllen
], relUrl
, MAX_URL
- urllen
- 1);
660 matchDomainName(const char *h
, const char *d
, uint flags
)
665 const bool hostIncludesSubdomains
= (*h
== '.');
677 * Start at the ends of the two strings and work towards the
680 while (xtolower(h
[--hl
]) == xtolower(d
[--dl
])) {
681 if (hl
== 0 && dl
== 0) {
683 * We made it all the way to the beginning of both
684 * strings without finding any difference.
691 * The host string is shorter than the domain string.
692 * There is only one case when this can be a match.
693 * If the domain is just one character longer, and if
694 * that character is a leading '.' then we call it a
698 if (1 == dl
&& '.' == d
[0])
706 * The domain string is shorter than the host string.
707 * This is a match only if the first domain character
712 if (flags
& mdnRejectSubsubDomains
) {
713 // Check for sub-sub domain and reject
714 while(--hl
>= 0 && h
[hl
] != '.');
716 // No sub-sub domain found, but reject if there is a
717 // leading dot in given host string (which is removed
718 // before the check is started).
719 return hostIncludesSubdomains
? 1 : 0;
721 return 1; // sub-sub domain, reject
730 * We found different characters in the same position (from the end).
733 // If the h has a form of "*.foo.com" and d has a form of "x.foo.com"
734 // then the h[hl] points to '*', h[hl+1] to '.' and d[dl] to 'x'
735 // The following checks are safe, the "h[hl + 1]" in the worst case is '\0'.
736 if ((flags
& mdnHonorWildcards
) && h
[hl
] == '*' && h
[hl
+ 1] == '.')
740 * If one of those character is '.' then its special. In order
741 * for splay tree sorting to work properly, "x-foo.com" must
742 * be greater than ".foo.com" even though '-' is less than '.'.
750 return (xtolower(h
[hl
]) - xtolower(d
[dl
]));
754 * return true if we can serve requests for this method.
757 urlCheckRequest(const HttpRequest
* r
)
760 /* protocol "independent" methods
762 * actually these methods are specific to HTTP:
763 * they are methods we recieve on our HTTP port,
764 * and if we had a FTP listener would not be relevant
767 * So, we should delegate them to HTTP. The problem is that we
768 * do not have a default protocol from the client side of HTTP.
771 if (r
->method
== Http::METHOD_CONNECT
)
774 // we support OPTIONS and TRACE directed at us (with a 501 reply, for now)
775 // we also support forwarding OPTIONS and TRACE, except for the *-URI ones
776 if (r
->method
== Http::METHOD_OPTIONS
|| r
->method
== Http::METHOD_TRACE
)
777 return (r
->header
.getInt64(Http::HdrType::MAX_FORWARDS
) == 0 || r
->url
.path() != URL::Asterisk());
779 if (r
->method
== Http::METHOD_PURGE
)
782 /* does method match the protocol? */
783 switch (r
->url
.getScheme()) {
785 case AnyP::PROTO_URN
:
787 case AnyP::PROTO_HTTP
:
789 case AnyP::PROTO_CACHE_OBJECT
:
793 case AnyP::PROTO_FTP
:
795 if (r
->method
== Http::METHOD_PUT
)
798 case AnyP::PROTO_GOPHER
:
800 case AnyP::PROTO_WAIS
:
802 case AnyP::PROTO_WHOIS
:
803 if (r
->method
== Http::METHOD_GET
)
805 else if (r
->method
== Http::METHOD_HEAD
)
810 case AnyP::PROTO_HTTPS
:
817 * Squid can't originate an SSL connection, so it should
818 * never receive an "https:" URL. It should always be
833 * Quick-n-dirty host extraction from a URL. Steps:
835 * Skip any '/' after the colon
836 * Copy the next SQUID_MAXHOSTNAMELEN bytes to host[]
837 * Look for an ending '/' or ':' and terminate
838 * Look for login info preceeded by '@'
845 char * extract(char const *url
);
848 static char Host
[SQUIDHOSTNAMELEN
];
849 void init(char const *);
850 void findHostStart();
851 void trimTrailingChars();
853 char const *hostStart
;
858 urlHostname(const char *url
)
860 return URLHostName().extract(url
);
863 char URLHostName::Host
[SQUIDHOSTNAMELEN
];
866 URLHostName::init(char const *aUrl
)
873 URLHostName::findHostStart()
875 if (NULL
== (hostStart
= strchr(url
, ':')))
880 while (*hostStart
!= '\0' && *hostStart
== '/')
883 if (*hostStart
== ']')
888 URLHostName::trimTrailingChars()
892 if ((t
= strchr(Host
, '/')))
895 if ((t
= strrchr(Host
, ':')))
898 if ((t
= strchr(Host
, ']')))
903 URLHostName::trimAuth()
907 if ((t
= strrchr(Host
, '@'))) {
909 memmove(Host
, t
, strlen(t
) + 1);
914 URLHostName::extract(char const *aUrl
)
919 if (hostStart
== NULL
)
922 xstrncpy(Host
, hostStart
, SQUIDHOSTNAMELEN
);
931 URL::URL(AnyP::UriScheme
const &aScheme
) :
933 hostIsNumeric_(false),