| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using System.Diagnostics; |
| | | 4 | | using System.Net.Security; |
| | | 5 | | |
| | | 6 | | namespace Ice.Internal; |
| | | 7 | | |
| | | 8 | | public interface EndpointI_connectors |
| | | 9 | | { |
| | | 10 | | void connectors(List<Connector> connectors); |
| | | 11 | | |
| | | 12 | | void exception(Ice.LocalException ex); |
| | | 13 | | } |
| | | 14 | | |
| | | 15 | | public abstract class EndpointI : Ice.Endpoint, IComparable<EndpointI> |
| | | 16 | | { |
| | | 17 | | public override string ToString() => |
| | | 18 | | // |
| | | 19 | | // WARNING: Certain features, such as proxy validation in Glacier2, |
| | | 20 | | // depend on the format of proxy strings. Changes to toString() and |
| | | 21 | | // methods called to generate parts of the reference string could break |
| | | 22 | | // these features. Please review for all features that depend on the |
| | | 23 | | // format of proxyToString() before changing this and related code. |
| | | 24 | | // |
| | 1 | 25 | | protocol() + options(); |
| | | 26 | | |
| | | 27 | | public abstract Ice.EndpointInfo getInfo(); |
| | | 28 | | |
| | | 29 | | public override bool Equals(object obj) |
| | | 30 | | { |
| | 1 | 31 | | if (!(obj is EndpointI)) |
| | | 32 | | { |
| | 0 | 33 | | return false; |
| | | 34 | | } |
| | 1 | 35 | | return CompareTo((EndpointI)obj) == 0; |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | public override int GetHashCode() // Avoids a compiler warning. |
| | | 39 | | { |
| | | 40 | | Debug.Assert(false); |
| | 0 | 41 | | return 0; |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | // |
| | | 45 | | // Marshal the endpoint. |
| | | 46 | | // |
| | | 47 | | public virtual void streamWrite(Ice.OutputStream s) |
| | | 48 | | { |
| | 1 | 49 | | s.startEncapsulation(); |
| | 1 | 50 | | streamWriteImpl(s); |
| | 1 | 51 | | s.endEncapsulation(); |
| | 1 | 52 | | } |
| | | 53 | | |
| | | 54 | | public abstract void streamWriteImpl(Ice.OutputStream s); |
| | | 55 | | |
| | | 56 | | // |
| | | 57 | | // Return the endpoint type. |
| | | 58 | | // |
| | | 59 | | public abstract short type(); |
| | | 60 | | |
| | | 61 | | // |
| | | 62 | | // Return the protocol name. |
| | | 63 | | // |
| | | 64 | | public abstract string protocol(); |
| | | 65 | | |
| | | 66 | | // |
| | | 67 | | // Return the timeout for the endpoint in milliseconds. 0 means |
| | | 68 | | // non-blocking, -1 means no timeout. |
| | | 69 | | // |
| | | 70 | | public abstract int timeout(); |
| | | 71 | | |
| | | 72 | | // |
| | | 73 | | // Return a new endpoint with a different timeout value, provided |
| | | 74 | | // that timeouts are supported by the endpoint. Otherwise the same |
| | | 75 | | // endpoint is returned. |
| | | 76 | | // |
| | | 77 | | public abstract EndpointI timeout(int t); |
| | | 78 | | |
| | | 79 | | // |
| | | 80 | | // Return the connection ID. |
| | | 81 | | // |
| | | 82 | | public abstract string connectionId(); |
| | | 83 | | |
| | | 84 | | // |
| | | 85 | | // Return a new endpoint with a different connection id. |
| | | 86 | | // |
| | | 87 | | public abstract EndpointI connectionId(string connectionId); |
| | | 88 | | |
| | | 89 | | // |
| | | 90 | | // Return true if the endpoints support bzip2 compress, or false |
| | | 91 | | // otherwise. |
| | | 92 | | // |
| | | 93 | | public abstract bool compress(); |
| | | 94 | | |
| | | 95 | | // |
| | | 96 | | // Return a new endpoint with a different compression value, |
| | | 97 | | // provided that compression is supported by the |
| | | 98 | | // endpoint. Otherwise the same endpoint is returned. |
| | | 99 | | // |
| | | 100 | | public abstract EndpointI compress(bool co); |
| | | 101 | | |
| | | 102 | | // |
| | | 103 | | // Return true if the endpoint is datagram-based. |
| | | 104 | | // |
| | | 105 | | public abstract bool datagram(); |
| | | 106 | | |
| | | 107 | | // |
| | | 108 | | // Return true if the endpoint is secure. |
| | | 109 | | // |
| | | 110 | | public abstract bool secure(); |
| | | 111 | | |
| | | 112 | | // |
| | | 113 | | // Return a server side transceiver for this endpoint, or null if a |
| | | 114 | | // transceiver can only be created by an acceptor. |
| | | 115 | | // |
| | | 116 | | public abstract Transceiver transceiver(); |
| | | 117 | | |
| | | 118 | | // |
| | | 119 | | // Return a connector for this endpoint, or empty list if no connector |
| | | 120 | | // is available. |
| | | 121 | | // |
| | | 122 | | public abstract void connectors_async(EndpointI_connectors callback); |
| | | 123 | | |
| | | 124 | | // |
| | | 125 | | // Return an acceptor for this endpoint, or null if no acceptors |
| | | 126 | | // is available. |
| | | 127 | | // |
| | | 128 | | public abstract Acceptor acceptor(string adapterName, SslServerAuthenticationOptions serverAuthenticationOptions); |
| | | 129 | | |
| | | 130 | | // Expand endpoint into separate endpoints for each IP address returned by the DNS resolver. |
| | | 131 | | // Used only for server endpoints. |
| | | 132 | | public abstract List<EndpointI> expandHost(); |
| | | 133 | | |
| | | 134 | | // Returns true when the most underlying endpoint is an IP endpoint with a loopback or multicast address. |
| | | 135 | | public abstract bool isLoopbackOrMulticast(); |
| | | 136 | | |
| | | 137 | | // Returns a new endpoint with the specified host (if not empty) and all local options cleared. May return this. |
| | | 138 | | public abstract EndpointI toPublishedEndpoint(string publishedHost); |
| | | 139 | | |
| | | 140 | | // |
| | | 141 | | // Check whether the endpoint is equivalent to another one. |
| | | 142 | | // |
| | | 143 | | public abstract bool equivalent(EndpointI endpoint); |
| | | 144 | | |
| | | 145 | | public abstract int CompareTo(EndpointI other); |
| | | 146 | | |
| | | 147 | | public abstract string options(); |
| | | 148 | | |
| | | 149 | | public virtual void initWithOptions(List<string> args) |
| | | 150 | | { |
| | 1 | 151 | | var unknown = new List<string>(); |
| | | 152 | | |
| | 1 | 153 | | string str = "'" + protocol() + " "; |
| | 1 | 154 | | foreach (string p in args) |
| | | 155 | | { |
| | 1 | 156 | | if (Ice.UtilInternal.StringUtil.findFirstOf(p, " \t\n\r") != -1) |
| | | 157 | | { |
| | 0 | 158 | | str += " \"" + p + "\""; |
| | | 159 | | } |
| | | 160 | | else |
| | | 161 | | { |
| | 1 | 162 | | str += " " + p; |
| | | 163 | | } |
| | | 164 | | } |
| | 1 | 165 | | str += "'"; |
| | | 166 | | |
| | 1 | 167 | | var knownOptions = new HashSet<string>(); |
| | | 168 | | |
| | 1 | 169 | | for (int n = 0; n < args.Count; ++n) |
| | | 170 | | { |
| | 1 | 171 | | string option = args[n]; |
| | 1 | 172 | | if (option.Length < 2 || option[0] != '-') |
| | | 173 | | { |
| | 0 | 174 | | unknown.Add(option); |
| | 0 | 175 | | continue; |
| | | 176 | | } |
| | | 177 | | |
| | 1 | 178 | | string argument = null; |
| | 1 | 179 | | if (n + 1 < args.Count && args[n + 1][0] != '-') |
| | | 180 | | { |
| | 1 | 181 | | argument = args[++n]; |
| | | 182 | | } |
| | | 183 | | |
| | 1 | 184 | | if (checkOption(option, argument, str)) |
| | | 185 | | { |
| | 1 | 186 | | if (!knownOptions.Add(option)) |
| | | 187 | | { |
| | 1 | 188 | | throw new ParseException($"Duplicate option '{option}' in endpoint {str}."); |
| | | 189 | | } |
| | | 190 | | } |
| | | 191 | | else |
| | | 192 | | { |
| | 1 | 193 | | unknown.Add(option); |
| | 1 | 194 | | if (argument != null) |
| | | 195 | | { |
| | 1 | 196 | | unknown.Add(argument); |
| | | 197 | | } |
| | | 198 | | } |
| | | 199 | | } |
| | | 200 | | |
| | 1 | 201 | | args.Clear(); |
| | 1 | 202 | | args.AddRange(unknown); |
| | 1 | 203 | | } |
| | | 204 | | |
| | | 205 | | protected virtual bool checkOption(string option, string argument, string endpoint) => |
| | | 206 | | // Must be overridden to check for options. |
| | 0 | 207 | | false; |
| | | 208 | | } |