]>
git.saurik.com Git - apple/security.git/blob - Network/target.cpp
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // target - target objects and their sub-components
31 // Produce a HostTarget with a default port inserted, if necessary.
33 HostTarget
HostTarget::defaultPort(IPPort defPort
) const
35 return HostTarget(scheme(), host(), port(defPort
), username(), password());
40 // Given a Target, construct a canonical proper URL string
42 string
HostTarget::urlForm() const
44 // form the :port optional part
47 sprintf(portPart
, ":%d", mPort
);
51 // build the whole form
54 snprintf(buffer
, sizeof(buffer
), "%s://%s:%s@%s%s",
55 scheme(), mUser
.c_str(), mPassword
.c_str(),
56 mHost
.name().c_str(), portPart
);
58 snprintf(buffer
, sizeof(buffer
), "%s://%s%s",
59 scheme(), mHost
.name().c_str(), portPart
);
64 string
Target::urlForm() const
66 return host
.urlForm() + path
;
70 bool HostTarget::operator == (const HostTarget
&other
) const
72 return mScheme
== other
.mScheme
73 && mHost
== other
.mHost
74 && mPort
== other
.mPort
75 && mUser
== other
.mUser
76 && mPassword
== other
.mPassword
;
79 bool HostTarget::operator < (const HostTarget
&other
) const
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
;
93 bool HostTarget::operator <= (const HostTarget
&other
) const
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
;
103 bool Target::operator == (const Target
&other
) const
105 return host
== other
.host
&& path
== other
.path
;
108 bool Target::operator <= (const Target
&other
) const
110 //@@@ be lenient on path matches? Usage?
111 return host
<= other
.host
&& path
== other
.path
;
115 } // end namespace Network
116 } // end namespace Security