]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved. | |
3 | * | |
4 | * The contents of this file constitute Original Code as defined in and are | |
5 | * subject to the Apple Public Source License Version 1.2 (the 'License'). | |
6 | * You may not use this file except in compliance with the License. Please obtain | |
7 | * a copy of the License at http://www.apple.com/publicsource and read it before | |
8 | * using this file. | |
9 | * | |
10 | * This Original Code and all software distributed under the License are | |
11 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS | |
12 | * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT | |
13 | * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | |
14 | * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the | |
15 | * specific language governing rights and limitations under the License. | |
16 | */ | |
17 | ||
18 | ||
19 | // | |
20 | // target - target objects and their sub-components | |
21 | // | |
22 | #include "target.h" | |
23 | #include "protocol.h" | |
24 | ||
25 | ||
26 | namespace Security { | |
27 | namespace Network { | |
28 | ||
29 | ||
30 | // | |
31 | // Produce a HostTarget with a default port inserted, if necessary. | |
32 | // | |
33 | HostTarget HostTarget::defaultPort(IPPort defPort) const | |
34 | { | |
35 | return HostTarget(scheme(), host(), port(defPort), username(), password()); | |
36 | } | |
37 | ||
38 | ||
39 | // | |
40 | // Given a Target, construct a canonical proper URL string | |
41 | // | |
42 | string HostTarget::urlForm() const | |
43 | { | |
44 | // form the :port optional part | |
45 | char portPart[10]; | |
46 | if (mPort) | |
47 | sprintf(portPart, ":%d", mPort); | |
48 | else | |
49 | portPart[0] = '\0'; | |
50 | ||
51 | // build the whole form | |
52 | char buffer[1024]; | |
53 | if (haveUserPass()) { | |
54 | snprintf(buffer, sizeof(buffer), "%s://%s:%s@%s%s", | |
55 | scheme(), mUser.c_str(), mPassword.c_str(), | |
56 | mHost.name().c_str(), portPart); | |
57 | } else { | |
58 | snprintf(buffer, sizeof(buffer), "%s://%s%s", | |
59 | scheme(), mHost.name().c_str(), portPart); | |
60 | } | |
61 | return buffer; | |
62 | } | |
63 | ||
64 | string Target::urlForm() const | |
65 | { | |
66 | return host.urlForm() + path; | |
67 | } | |
68 | ||
69 | ||
70 | bool HostTarget::operator == (const HostTarget &other) const | |
71 | { | |
72 | return mScheme == other.mScheme | |
73 | && mHost == other.mHost | |
74 | && mPort == other.mPort | |
75 | && mUser == other.mUser | |
76 | && mPassword == other.mPassword; | |
77 | } | |
78 | ||
79 | bool HostTarget::operator < (const HostTarget &other) const | |
80 | { | |
81 | // arbitrary lexicographic ordering | |
82 | if (mScheme != other.mScheme) | |
83 | return mScheme < other.mScheme; | |
84 | if (mHost != other.mHost) | |
85 | return mHost < other.mHost; | |
86 | if (mPort != other.mPort) | |
87 | return mPort < other.mPort; | |
88 | if (mUser != other.mUser) | |
89 | return mUser < other.mUser; | |
90 | return mPassword < other.mPassword; | |
91 | } | |
92 | ||
93 | bool HostTarget::operator <= (const HostTarget &other) const | |
94 | { | |
95 | //@@@ be lenient on subsume-matching empty users/passwords? Distinguish spec/unspec? | |
96 | return mHost <= other.mHost | |
97 | && mScheme == other.mScheme | |
98 | && mPort == other.mPort | |
99 | && mUser == other.mUser | |
100 | && mPassword == other.mPassword; | |
101 | } | |
102 | ||
103 | bool Target::operator == (const Target &other) const | |
104 | { | |
105 | return host == other.host && path == other.path; | |
106 | } | |
107 | ||
108 | bool Target::operator <= (const Target &other) const | |
109 | { | |
110 | //@@@ be lenient on path matches? Usage? | |
111 | return host <= other.host && path == other.path; | |
112 | } | |
113 | ||
114 | ||
115 | } // end namespace Network | |
116 | } // end namespace Security |