]>
git.saurik.com Git - apple/security.git/blob - Network/target.h
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
25 #include <Security/ip++.h>
26 #include <Security/hosts.h>
33 using namespace IPPlusPlus
;
40 // A HostTarget is the "host part" of a full access target.
41 // HostTargets are suitable for use as keys in STL containers.
45 HostTarget(const char *scheme
, Host h
, IPPort p
, string user
= "", string password
= "")
46 : mScheme(scheme
), mHost(h
), mPort(p
), mUser(user
), mPassword(password
) { }
48 const char *scheme() const { return mScheme
.c_str(); }
49 const Host
&host() const { return mHost
; }
50 IPPort
port(IPPort defaultPort
= 0) const { return mPort
? mPort
: defaultPort
; }
52 //@@@ this should probably be replaced with pluggable authentication schemes
53 bool haveUserPass() const { return mUser
!= ""; }
54 string
username() const { return mUser
; }
55 string
password() const { return mPassword
; }
57 bool operator == (const HostTarget
&other
) const; // equality
58 bool operator < (const HostTarget
&other
) const; // less-than for sorting
59 bool operator <= (const HostTarget
&other
) const; // proper nonstrict subsumption
61 HostTarget
defaultPort(IPPort def
) const;
63 string
urlForm() const; // canonical URL prefix form (without /path postfix)
66 string mScheme
; // URL scheme
67 Host mHost
; // host name or number; no default
68 IPPort mPort
; // port number; zero to use protocol default
69 string mUser
; // username; default empty
70 string mPassword
; // password; default empty
76 // Targets are suitable for use as keys in STL functions.
80 Target(const HostTarget
&theHost
, const char *thePath
) : host(theHost
), path(thePath
) { }
81 Target(const HostTarget
&theHost
, string thePath
) : host(theHost
), path(thePath
) { }
82 Target(const char *scheme
, Host h
, IPPort p
, const char *thePath
)
83 : host(scheme
, h
, p
), path(thePath
) { }
85 bool operator == (const Target
&other
) const;
86 bool operator <= (const Target
&other
) const;
88 operator const HostTarget
&() const { return host
; }
90 string
urlForm() const; // construct canonical URL form
92 const HostTarget host
;
97 } // end namespace Network
98 } // end namespace Security