]> git.saurik.com Git - apple/security.git/blob - Network/target.h
Security-54.tar.gz
[apple/security.git] / Network / target.h
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 #ifndef _H_TARGET
23 #define _H_TARGET
24
25 #include <Security/ip++.h>
26 #include <Security/hosts.h>
27 #include <set>
28
29
30 namespace Security {
31 namespace Network {
32
33 using namespace IPPlusPlus;
34
35
36 class Protocol;
37
38
39 //
40 // A HostTarget is the "host part" of a full access target.
41 // HostTargets are suitable for use as keys in STL containers.
42 //
43 class HostTarget {
44 public:
45 HostTarget(const char *scheme, Host h, IPPort p, string user = "", string password = "")
46 : mScheme(scheme), mHost(h), mPort(p), mUser(user), mPassword(password) { }
47
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; }
51
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; }
56
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
60
61 HostTarget defaultPort(IPPort def) const;
62
63 string urlForm() const; // canonical URL prefix form (without /path postfix)
64
65 private:
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
71 };
72
73
74 //
75 // Targets
76 // Targets are suitable for use as keys in STL functions.
77 //
78 class Target {
79 public:
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) { }
84
85 bool operator == (const Target &other) const;
86 bool operator <= (const Target &other) const;
87
88 operator const HostTarget &() const { return host; }
89
90 string urlForm() const; // construct canonical URL form
91
92 const HostTarget host;
93 const string path;
94 };
95
96
97 } // end namespace Network
98 } // end namespace Security
99
100
101 #endif _H_TARGET