| | | 1 | | // Copyright (c) ZeroC, Inc. |
| | | 2 | | |
| | | 3 | | using System.Diagnostics; |
| | | 4 | | using System.Text; |
| | | 5 | | |
| | | 6 | | namespace Ice.Internal; |
| | | 7 | | |
| | | 8 | | internal class ReferenceFactory |
| | | 9 | | { |
| | | 10 | | internal Reference |
| | | 11 | | create(Ice.Identity ident, string facet, Reference tmpl, EndpointI[] endpoints) |
| | | 12 | | { |
| | 1 | 13 | | if (ident.name.Length == 0 && ident.category.Length == 0) |
| | | 14 | | { |
| | 0 | 15 | | return null; |
| | | 16 | | } |
| | | 17 | | |
| | 1 | 18 | | return create( |
| | 1 | 19 | | ident, |
| | 1 | 20 | | facet, |
| | 1 | 21 | | tmpl.getMode(), |
| | 1 | 22 | | tmpl.getProtocol(), |
| | 1 | 23 | | tmpl.getEncoding(), |
| | 1 | 24 | | endpoints, |
| | 1 | 25 | | null, |
| | 1 | 26 | | null); |
| | | 27 | | } |
| | | 28 | | |
| | | 29 | | internal Reference |
| | | 30 | | create(Ice.Identity ident, string facet, Reference tmpl, string adapterId) |
| | | 31 | | { |
| | 1 | 32 | | if (ident.name.Length == 0 && ident.category.Length == 0) |
| | | 33 | | { |
| | 0 | 34 | | return null; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | // |
| | | 38 | | // Create new reference |
| | | 39 | | // |
| | 1 | 40 | | return create( |
| | 1 | 41 | | ident, |
| | 1 | 42 | | facet, |
| | 1 | 43 | | tmpl.getMode(), |
| | 1 | 44 | | tmpl.getProtocol(), |
| | 1 | 45 | | tmpl.getEncoding(), |
| | 1 | 46 | | null, |
| | 1 | 47 | | adapterId, |
| | 1 | 48 | | null); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | internal Reference create(Ice.Identity ident, Ice.ConnectionI connection) |
| | | 52 | | { |
| | 1 | 53 | | if (ident.name.Length == 0 && ident.category.Length == 0) |
| | | 54 | | { |
| | 0 | 55 | | return null; |
| | | 56 | | } |
| | | 57 | | |
| | | 58 | | // |
| | | 59 | | // Create new reference |
| | | 60 | | // |
| | 1 | 61 | | return new FixedReference( |
| | 1 | 62 | | _instance, |
| | 1 | 63 | | _communicator, |
| | 1 | 64 | | ident, |
| | 1 | 65 | | "", // Facet |
| | 1 | 66 | | connection.endpoint().datagram() ? Reference.Mode.ModeDatagram : Reference.Mode.ModeTwoway, |
| | 1 | 67 | | compress: null, |
| | 1 | 68 | | Protocol.Protocol_1_0, |
| | 1 | 69 | | _instance.defaultsAndOverrides().defaultEncoding, |
| | 1 | 70 | | connection, |
| | 1 | 71 | | TimeSpan.FromMilliseconds(-1), |
| | 1 | 72 | | null); |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | internal Reference copy(Reference r) |
| | | 76 | | { |
| | 1 | 77 | | Ice.Identity ident = r.getIdentity(); |
| | 1 | 78 | | if (ident.name.Length == 0 && ident.category.Length == 0) |
| | | 79 | | { |
| | 0 | 80 | | return null; |
| | | 81 | | } |
| | 1 | 82 | | return r.Clone(); |
| | | 83 | | } |
| | | 84 | | |
| | | 85 | | internal Reference create(string s, string propertyPrefix) |
| | | 86 | | { |
| | 1 | 87 | | if (s.Length == 0) |
| | | 88 | | { |
| | 1 | 89 | | return null; |
| | | 90 | | } |
| | | 91 | | |
| | | 92 | | const string delim = " \t\n\r"; |
| | | 93 | | |
| | | 94 | | int beg; |
| | 1 | 95 | | int end = 0; |
| | | 96 | | |
| | 1 | 97 | | beg = Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, end); |
| | 1 | 98 | | if (beg == -1) |
| | | 99 | | { |
| | 0 | 100 | | throw new ParseException($"no non-whitespace characters found in proxy string '{s}'"); |
| | | 101 | | } |
| | | 102 | | |
| | 1 | 103 | | end = Ice.UtilInternal.StringUtil.checkQuote(s, beg); |
| | | 104 | | |
| | | 105 | | // |
| | | 106 | | // Extract the identity, which may be enclosed in single |
| | | 107 | | // or double quotation marks. |
| | | 108 | | // |
| | | 109 | | string idstr; |
| | 1 | 110 | | if (end == -1) |
| | | 111 | | { |
| | 1 | 112 | | throw new ParseException($"mismatched quotes around identity in proxy string '{s}'"); |
| | | 113 | | } |
| | 1 | 114 | | else if (end == 0) |
| | | 115 | | { |
| | 1 | 116 | | end = Ice.UtilInternal.StringUtil.findFirstOf(s, delim + ":@", beg); |
| | 1 | 117 | | if (end == -1) |
| | | 118 | | { |
| | 1 | 119 | | end = s.Length; |
| | | 120 | | } |
| | 1 | 121 | | idstr = s[beg..end]; |
| | | 122 | | } |
| | | 123 | | else |
| | | 124 | | { |
| | 1 | 125 | | beg++; // Skip leading quote |
| | 1 | 126 | | idstr = s[beg..end]; |
| | 1 | 127 | | end++; // Skip trailing quote |
| | | 128 | | } |
| | | 129 | | |
| | 1 | 130 | | if (beg == end) |
| | | 131 | | { |
| | 0 | 132 | | throw new ParseException($"no identity in proxy string '{s}'"); |
| | | 133 | | } |
| | | 134 | | |
| | | 135 | | // |
| | | 136 | | // Parsing the identity may raise ParseException. |
| | | 137 | | // |
| | 1 | 138 | | Ice.Identity ident = Ice.Util.stringToIdentity(idstr); |
| | | 139 | | |
| | 1 | 140 | | if (ident.name.Length == 0) |
| | | 141 | | { |
| | | 142 | | // |
| | | 143 | | // An identity with an empty name and a non-empty |
| | | 144 | | // category is illegal. |
| | | 145 | | // |
| | 1 | 146 | | if (ident.category.Length > 0) |
| | | 147 | | { |
| | 0 | 148 | | throw new ParseException("The category of a null Ice object identity must be empty."); |
| | | 149 | | } |
| | | 150 | | // |
| | | 151 | | // Treat a stringified proxy containing two double |
| | | 152 | | // quotes ("") the same as an empty string, i.e., |
| | | 153 | | // a null proxy, but only if nothing follows the |
| | | 154 | | // quotes. |
| | | 155 | | // |
| | 1 | 156 | | else if (Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, end) != -1) |
| | | 157 | | { |
| | 1 | 158 | | throw new ParseException($"invalid characters after identity in proxy string '{s}'"); |
| | | 159 | | } |
| | | 160 | | else |
| | | 161 | | { |
| | 1 | 162 | | return null; |
| | | 163 | | } |
| | | 164 | | } |
| | | 165 | | |
| | 1 | 166 | | string facet = ""; |
| | 1 | 167 | | Reference.Mode mode = Reference.Mode.ModeTwoway; |
| | 1 | 168 | | Ice.EncodingVersion encoding = _instance.defaultsAndOverrides().defaultEncoding; |
| | 1 | 169 | | Ice.ProtocolVersion protocol = Protocol.Protocol_1_0; |
| | | 170 | | while (true) |
| | | 171 | | { |
| | 1 | 172 | | beg = Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, end); |
| | 1 | 173 | | if (beg == -1) |
| | | 174 | | { |
| | | 175 | | break; |
| | | 176 | | } |
| | | 177 | | |
| | 1 | 178 | | if (s[beg] == ':' || s[beg] == '@') |
| | | 179 | | { |
| | | 180 | | break; |
| | | 181 | | } |
| | | 182 | | |
| | 1 | 183 | | end = Ice.UtilInternal.StringUtil.findFirstOf(s, delim + ":@", beg); |
| | 1 | 184 | | if (end == -1) |
| | | 185 | | { |
| | 1 | 186 | | end = s.Length; |
| | | 187 | | } |
| | | 188 | | |
| | 1 | 189 | | if (beg == end) |
| | | 190 | | { |
| | | 191 | | break; |
| | | 192 | | } |
| | | 193 | | |
| | 1 | 194 | | string option = s[beg..end]; |
| | 1 | 195 | | if (option.Length != 2 || option[0] != '-') |
| | | 196 | | { |
| | 1 | 197 | | throw new ParseException($"expected a proxy option but found '{option}' in proxy string '{s}'"); |
| | | 198 | | } |
| | | 199 | | |
| | | 200 | | // |
| | | 201 | | // Check for the presence of an option argument. The |
| | | 202 | | // argument may be enclosed in single or double |
| | | 203 | | // quotation marks. |
| | | 204 | | // |
| | 1 | 205 | | string argument = null; |
| | 1 | 206 | | int argumentBeg = Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, end); |
| | 1 | 207 | | if (argumentBeg != -1) |
| | | 208 | | { |
| | 1 | 209 | | char ch = s[argumentBeg]; |
| | 1 | 210 | | if (ch != '@' && ch != ':' && ch != '-') |
| | | 211 | | { |
| | 1 | 212 | | beg = argumentBeg; |
| | 1 | 213 | | end = Ice.UtilInternal.StringUtil.checkQuote(s, beg); |
| | 1 | 214 | | if (end == -1) |
| | | 215 | | { |
| | 1 | 216 | | throw new ParseException( |
| | 1 | 217 | | $"mismatched quotes around value for {option} option in proxy string '{s}'"); |
| | | 218 | | } |
| | 1 | 219 | | else if (end == 0) |
| | | 220 | | { |
| | 1 | 221 | | end = Ice.UtilInternal.StringUtil.findFirstOf(s, delim + ":@", beg); |
| | 1 | 222 | | if (end == -1) |
| | | 223 | | { |
| | 1 | 224 | | end = s.Length; |
| | | 225 | | } |
| | 1 | 226 | | argument = s[beg..end]; |
| | | 227 | | } |
| | | 228 | | else |
| | | 229 | | { |
| | 1 | 230 | | beg++; // Skip leading quote |
| | 1 | 231 | | argument = s[beg..end]; |
| | 1 | 232 | | end++; // Skip trailing quote |
| | | 233 | | } |
| | | 234 | | } |
| | | 235 | | } |
| | | 236 | | |
| | | 237 | | // |
| | | 238 | | // If any new options are added here, |
| | | 239 | | // Ice.Internal::Reference::toString() and its derived classes must be updated as well. |
| | | 240 | | // |
| | 1 | 241 | | switch (option[1]) |
| | | 242 | | { |
| | | 243 | | case 'f': |
| | | 244 | | { |
| | 1 | 245 | | if (argument == null) |
| | | 246 | | { |
| | 0 | 247 | | throw new ParseException($"no argument provided for -f option in proxy string '{s}'"); |
| | | 248 | | } |
| | | 249 | | |
| | | 250 | | try |
| | | 251 | | { |
| | 1 | 252 | | facet = Ice.UtilInternal.StringUtil.unescapeString(argument, 0, argument.Length, ""); |
| | 1 | 253 | | } |
| | 0 | 254 | | catch (ArgumentException argEx) |
| | | 255 | | { |
| | 0 | 256 | | throw new ParseException($"invalid facet in proxy string '{s}'", argEx); |
| | | 257 | | } |
| | | 258 | | break; |
| | | 259 | | } |
| | | 260 | | |
| | | 261 | | case 't': |
| | | 262 | | { |
| | 1 | 263 | | if (argument != null) |
| | | 264 | | { |
| | 0 | 265 | | throw new ParseException( |
| | 0 | 266 | | $"unexpected argument '{argument}' provided for -t option in proxy string '{s}'"); |
| | | 267 | | } |
| | 1 | 268 | | mode = Reference.Mode.ModeTwoway; |
| | 1 | 269 | | break; |
| | | 270 | | } |
| | | 271 | | |
| | | 272 | | case 'o': |
| | | 273 | | { |
| | 1 | 274 | | if (argument != null) |
| | | 275 | | { |
| | 0 | 276 | | throw new ParseException( |
| | 0 | 277 | | $"unexpected argument '{argument}' provided for -o option in proxy string '{s}'"); |
| | | 278 | | } |
| | 1 | 279 | | mode = Reference.Mode.ModeOneway; |
| | 1 | 280 | | break; |
| | | 281 | | } |
| | | 282 | | |
| | | 283 | | case 'O': |
| | | 284 | | { |
| | 1 | 285 | | if (argument != null) |
| | | 286 | | { |
| | 0 | 287 | | throw new ParseException( |
| | 0 | 288 | | $"unexpected argument '{argument}' provided for -O option in proxy string '{s}'"); |
| | | 289 | | } |
| | 1 | 290 | | mode = Reference.Mode.ModeBatchOneway; |
| | 1 | 291 | | break; |
| | | 292 | | } |
| | | 293 | | |
| | | 294 | | case 'd': |
| | | 295 | | { |
| | 1 | 296 | | if (argument != null) |
| | | 297 | | { |
| | 0 | 298 | | throw new ParseException( |
| | 0 | 299 | | $"unexpected argument '{argument}' provided for -d option in proxy string '{s}'"); |
| | | 300 | | } |
| | 1 | 301 | | mode = Reference.Mode.ModeDatagram; |
| | 1 | 302 | | break; |
| | | 303 | | } |
| | | 304 | | |
| | | 305 | | case 'D': |
| | | 306 | | { |
| | 1 | 307 | | if (argument != null) |
| | | 308 | | { |
| | 0 | 309 | | throw new ParseException( |
| | 0 | 310 | | $"unexpected argument '{argument}' provided for -D option in proxy string '{s}'"); |
| | | 311 | | } |
| | 1 | 312 | | mode = Reference.Mode.ModeBatchDatagram; |
| | 1 | 313 | | break; |
| | | 314 | | } |
| | | 315 | | |
| | | 316 | | case 's': |
| | | 317 | | { |
| | 1 | 318 | | if (argument != null) |
| | | 319 | | { |
| | 0 | 320 | | throw new ParseException( |
| | 0 | 321 | | $"unexpected argument '{argument}' provided for -s option in proxy string '{s}'"); |
| | | 322 | | } |
| | | 323 | | // Ignored. Only kept for backwards compatibility. |
| | | 324 | | break; |
| | | 325 | | } |
| | | 326 | | |
| | | 327 | | case 'e': |
| | | 328 | | { |
| | 1 | 329 | | if (argument == null) |
| | | 330 | | { |
| | 0 | 331 | | throw new ParseException($"no argument provided for -e option in proxy string '{s}'"); |
| | | 332 | | } |
| | | 333 | | |
| | | 334 | | try |
| | | 335 | | { |
| | 1 | 336 | | encoding = Protocol.stringToEncodingVersion(argument); |
| | 1 | 337 | | } |
| | 0 | 338 | | catch (ParseException e) |
| | | 339 | | { |
| | 0 | 340 | | throw new ParseException($"invalid encoding version '{argument}' in proxy string '{s}'", e); |
| | | 341 | | } |
| | | 342 | | break; |
| | | 343 | | } |
| | | 344 | | |
| | | 345 | | case 'p': |
| | | 346 | | { |
| | 1 | 347 | | if (argument == null) |
| | | 348 | | { |
| | 0 | 349 | | throw new ParseException($"no argument provided for -p option in proxy string '{s}'"); |
| | | 350 | | } |
| | | 351 | | |
| | | 352 | | try |
| | | 353 | | { |
| | 1 | 354 | | protocol = Protocol.stringToProtocolVersion(argument); |
| | 1 | 355 | | } |
| | 0 | 356 | | catch (ParseException e) |
| | | 357 | | { |
| | 0 | 358 | | throw new ParseException($"invalid protocol version '{argument}' in proxy string '{s}'", e); |
| | | 359 | | } |
| | | 360 | | break; |
| | | 361 | | } |
| | | 362 | | |
| | | 363 | | default: |
| | | 364 | | { |
| | 0 | 365 | | throw new ParseException($"unknown option '{option}' in proxy string '{s}'"); |
| | | 366 | | } |
| | | 367 | | } |
| | | 368 | | } |
| | | 369 | | |
| | 1 | 370 | | if (beg == -1) |
| | | 371 | | { |
| | 1 | 372 | | return create(ident, facet, mode, protocol, encoding, null, null, propertyPrefix); |
| | | 373 | | } |
| | | 374 | | |
| | 1 | 375 | | var endpoints = new List<EndpointI>(); |
| | | 376 | | |
| | 1 | 377 | | if (s[beg] == ':') |
| | | 378 | | { |
| | 1 | 379 | | var unknownEndpoints = new List<string>(); |
| | 1 | 380 | | end = beg; |
| | | 381 | | |
| | 1 | 382 | | while (end < s.Length && s[end] == ':') |
| | | 383 | | { |
| | 1 | 384 | | beg = end + 1; |
| | | 385 | | |
| | 1 | 386 | | end = beg; |
| | 1 | 387 | | while (true) |
| | | 388 | | { |
| | 1 | 389 | | end = s.IndexOf(':', end); |
| | 1 | 390 | | if (end == -1) |
| | | 391 | | { |
| | 1 | 392 | | end = s.Length; |
| | 1 | 393 | | break; |
| | | 394 | | } |
| | | 395 | | else |
| | | 396 | | { |
| | 1 | 397 | | bool quoted = false; |
| | 1 | 398 | | int quote = beg; |
| | 1 | 399 | | while (true) |
| | | 400 | | { |
| | 1 | 401 | | quote = s.IndexOf('\"', quote); |
| | 1 | 402 | | if (quote == -1 || end < quote) |
| | | 403 | | { |
| | | 404 | | break; |
| | | 405 | | } |
| | | 406 | | else |
| | | 407 | | { |
| | 1 | 408 | | quote = s.IndexOf('\"', ++quote); |
| | 1 | 409 | | if (quote == -1) |
| | | 410 | | { |
| | | 411 | | break; |
| | | 412 | | } |
| | 1 | 413 | | else if (end < quote) |
| | | 414 | | { |
| | 1 | 415 | | quoted = true; |
| | 1 | 416 | | break; |
| | | 417 | | } |
| | 1 | 418 | | ++quote; |
| | | 419 | | } |
| | | 420 | | } |
| | 1 | 421 | | if (!quoted) |
| | | 422 | | { |
| | | 423 | | break; |
| | | 424 | | } |
| | 1 | 425 | | ++end; |
| | | 426 | | } |
| | | 427 | | } |
| | | 428 | | |
| | 1 | 429 | | string es = s[beg..end]; |
| | 1 | 430 | | EndpointI endp = _instance.endpointFactoryManager().create(es, false); |
| | 1 | 431 | | if (endp != null) |
| | | 432 | | { |
| | 1 | 433 | | endpoints.Add(endp); |
| | | 434 | | } |
| | | 435 | | else |
| | | 436 | | { |
| | 1 | 437 | | unknownEndpoints.Add(es); |
| | | 438 | | } |
| | | 439 | | } |
| | 1 | 440 | | if (endpoints.Count == 0) |
| | | 441 | | { |
| | | 442 | | Debug.Assert(unknownEndpoints.Count > 0); |
| | 1 | 443 | | throw new ParseException($"invalid endpoint '{unknownEndpoints[0]}' in '{s}'"); |
| | | 444 | | } |
| | 1 | 445 | | else if (unknownEndpoints.Count != 0 && |
| | 1 | 446 | | _instance.initializationData().properties.getIcePropertyAsInt("Ice.Warn.Endpoints") > 0) |
| | | 447 | | { |
| | 0 | 448 | | var msg = new StringBuilder("Proxy contains unknown endpoints:"); |
| | 0 | 449 | | int sz = unknownEndpoints.Count; |
| | 0 | 450 | | for (int idx = 0; idx < sz; ++idx) |
| | | 451 | | { |
| | 0 | 452 | | msg.Append(" `"); |
| | 0 | 453 | | msg.Append(unknownEndpoints[idx]); |
| | 0 | 454 | | msg.Append('\''); |
| | | 455 | | } |
| | 0 | 456 | | _instance.initializationData().logger.warning(msg.ToString()); |
| | | 457 | | } |
| | | 458 | | |
| | 1 | 459 | | EndpointI[] ep = endpoints.ToArray(); |
| | 1 | 460 | | return create(ident, facet, mode, protocol, encoding, ep, null, propertyPrefix); |
| | | 461 | | } |
| | 1 | 462 | | else if (s[beg] == '@') |
| | | 463 | | { |
| | 1 | 464 | | beg = Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, beg + 1); |
| | 1 | 465 | | if (beg == -1) |
| | | 466 | | { |
| | 0 | 467 | | throw new ParseException($"missing adapter ID in proxy string '{s}'"); |
| | | 468 | | } |
| | | 469 | | |
| | 1 | 470 | | end = Ice.UtilInternal.StringUtil.checkQuote(s, beg); |
| | | 471 | | |
| | | 472 | | string adapterstr; |
| | 1 | 473 | | if (end == -1) |
| | | 474 | | { |
| | 0 | 475 | | throw new ParseException($"mismatched quotes around adapter ID in proxy string '{s}'"); |
| | | 476 | | } |
| | 1 | 477 | | else if (end == 0) |
| | | 478 | | { |
| | 1 | 479 | | end = Ice.UtilInternal.StringUtil.findFirstOf(s, delim, beg); |
| | 1 | 480 | | if (end == -1) |
| | | 481 | | { |
| | 1 | 482 | | end = s.Length; |
| | | 483 | | } |
| | 1 | 484 | | adapterstr = s[beg..end]; |
| | | 485 | | } |
| | | 486 | | else |
| | | 487 | | { |
| | 1 | 488 | | beg++; // Skip leading quote |
| | 1 | 489 | | adapterstr = s[beg..end]; |
| | 1 | 490 | | end++; // Skip trailing quote |
| | | 491 | | } |
| | | 492 | | |
| | 1 | 493 | | if (end != s.Length && Ice.UtilInternal.StringUtil.findFirstNotOf(s, delim, end) != -1) |
| | | 494 | | { |
| | 1 | 495 | | throw new ParseException($"invalid characters after adapter ID in proxy string '{s}'"); |
| | | 496 | | } |
| | | 497 | | |
| | | 498 | | string adapter; |
| | | 499 | | try |
| | | 500 | | { |
| | 1 | 501 | | adapter = Ice.UtilInternal.StringUtil.unescapeString(adapterstr, 0, adapterstr.Length, ""); |
| | 1 | 502 | | } |
| | 0 | 503 | | catch (ArgumentException argEx) |
| | | 504 | | { |
| | 0 | 505 | | throw new ParseException($"invalid adapter ID in proxy string '{s}'", argEx); |
| | | 506 | | } |
| | 1 | 507 | | if (adapter.Length == 0) |
| | | 508 | | { |
| | 0 | 509 | | throw new ParseException($"empty adapter ID in proxy string '{s}'"); |
| | | 510 | | } |
| | 1 | 511 | | return create(ident, facet, mode, protocol, encoding, null, adapter, propertyPrefix); |
| | | 512 | | } |
| | | 513 | | |
| | 0 | 514 | | throw new ParseException($"malformed proxy string '{s}'"); |
| | | 515 | | } |
| | | 516 | | |
| | | 517 | | internal Reference create(Ice.Identity ident, Ice.InputStream s) |
| | | 518 | | { |
| | | 519 | | // |
| | | 520 | | // Don't read the identity here. Operations calling this |
| | | 521 | | // constructor read the identity, and pass it as a parameter. |
| | | 522 | | // |
| | | 523 | | |
| | 1 | 524 | | if (ident.name.Length == 0 && ident.category.Length == 0) |
| | | 525 | | { |
| | 0 | 526 | | return null; |
| | | 527 | | } |
| | | 528 | | |
| | | 529 | | // |
| | | 530 | | // For compatibility with the old FacetPath. |
| | | 531 | | // |
| | 1 | 532 | | string[] facetPath = s.readStringSeq(); |
| | | 533 | | string facet; |
| | 1 | 534 | | if (facetPath.Length > 0) |
| | | 535 | | { |
| | 0 | 536 | | if (facetPath.Length > 1) |
| | | 537 | | { |
| | 0 | 538 | | throw new MarshalException($"Received invalid facet path with {facetPath.Length} elements."); |
| | | 539 | | } |
| | 0 | 540 | | facet = facetPath[0]; |
| | | 541 | | } |
| | | 542 | | else |
| | | 543 | | { |
| | 1 | 544 | | facet = ""; |
| | | 545 | | } |
| | | 546 | | |
| | 1 | 547 | | int mode = s.readByte(); |
| | 1 | 548 | | if (mode < 0 || mode > (int)Reference.Mode.ModeBatchDatagram) |
| | | 549 | | { |
| | 0 | 550 | | throw new MarshalException($"Received invalid proxy mode {mode}"); |
| | | 551 | | } |
| | | 552 | | |
| | 1 | 553 | | _ = s.readBool(); // the secure field is no longer used |
| | | 554 | | |
| | | 555 | | Ice.ProtocolVersion protocol; |
| | | 556 | | Ice.EncodingVersion encoding; |
| | 1 | 557 | | if (!s.getEncoding().Equals(Ice.Util.Encoding_1_0)) |
| | | 558 | | { |
| | 1 | 559 | | protocol = new Ice.ProtocolVersion(s); |
| | 1 | 560 | | encoding = new Ice.EncodingVersion(s); |
| | | 561 | | } |
| | | 562 | | else |
| | | 563 | | { |
| | 1 | 564 | | protocol = Protocol.Protocol_1_0; |
| | 1 | 565 | | encoding = Ice.Util.Encoding_1_0; |
| | | 566 | | } |
| | | 567 | | |
| | 1 | 568 | | EndpointI[] endpoints = null; |
| | 1 | 569 | | string adapterId = ""; |
| | | 570 | | |
| | 1 | 571 | | int sz = s.readSize(); |
| | 1 | 572 | | if (sz > 0) |
| | | 573 | | { |
| | 1 | 574 | | endpoints = new EndpointI[sz]; |
| | 1 | 575 | | for (int i = 0; i < sz; i++) |
| | | 576 | | { |
| | 1 | 577 | | endpoints[i] = _instance.endpointFactoryManager().read(s); |
| | | 578 | | } |
| | | 579 | | } |
| | | 580 | | else |
| | | 581 | | { |
| | 1 | 582 | | adapterId = s.readString(); |
| | | 583 | | } |
| | | 584 | | |
| | 1 | 585 | | return create(ident, facet, (Reference.Mode)mode, protocol, encoding, endpoints, adapterId, null); |
| | | 586 | | } |
| | | 587 | | |
| | | 588 | | internal ReferenceFactory setDefaultRouter(Ice.RouterPrx defaultRouter) |
| | | 589 | | { |
| | 1 | 590 | | if (_defaultRouter == null ? defaultRouter == null : _defaultRouter.Equals(defaultRouter)) |
| | | 591 | | { |
| | 0 | 592 | | return this; |
| | | 593 | | } |
| | | 594 | | |
| | 1 | 595 | | var factory = new ReferenceFactory(_instance, _communicator); |
| | 1 | 596 | | factory._defaultLocator = _defaultLocator; |
| | 1 | 597 | | factory._defaultRouter = defaultRouter; |
| | 1 | 598 | | return factory; |
| | | 599 | | } |
| | | 600 | | |
| | 1 | 601 | | internal Ice.RouterPrx getDefaultRouter() => _defaultRouter; |
| | | 602 | | |
| | | 603 | | internal ReferenceFactory setDefaultLocator(Ice.LocatorPrx defaultLocator) |
| | | 604 | | { |
| | 1 | 605 | | if (_defaultLocator == null ? defaultLocator == null : _defaultLocator.Equals(defaultLocator)) |
| | | 606 | | { |
| | 0 | 607 | | return this; |
| | | 608 | | } |
| | | 609 | | |
| | 1 | 610 | | var factory = new ReferenceFactory(_instance, _communicator); |
| | 1 | 611 | | factory._defaultLocator = defaultLocator; |
| | 1 | 612 | | factory._defaultRouter = _defaultRouter; |
| | 1 | 613 | | return factory; |
| | | 614 | | } |
| | | 615 | | |
| | 1 | 616 | | internal Ice.LocatorPrx getDefaultLocator() => _defaultLocator; |
| | | 617 | | |
| | | 618 | | // |
| | | 619 | | // Only for use by Instance |
| | | 620 | | // |
| | 1 | 621 | | internal ReferenceFactory(Instance instance, Ice.Communicator communicator) |
| | | 622 | | { |
| | 1 | 623 | | _instance = instance; |
| | 1 | 624 | | _communicator = communicator; |
| | 1 | 625 | | } |
| | | 626 | | |
| | | 627 | | private Reference create( |
| | | 628 | | Ice.Identity ident, |
| | | 629 | | string facet, |
| | | 630 | | Reference.Mode mode, |
| | | 631 | | Ice.ProtocolVersion protocol, |
| | | 632 | | Ice.EncodingVersion encoding, |
| | | 633 | | EndpointI[] endpoints, |
| | | 634 | | string adapterId, |
| | | 635 | | string propertyPrefix) |
| | | 636 | | { |
| | 1 | 637 | | DefaultsAndOverrides defaultsAndOverrides = _instance.defaultsAndOverrides(); |
| | | 638 | | |
| | | 639 | | // |
| | | 640 | | // Default local proxy options. |
| | | 641 | | // |
| | 1 | 642 | | LocatorInfo locatorInfo = null; |
| | 1 | 643 | | if (_defaultLocator != null) |
| | | 644 | | { |
| | 1 | 645 | | if (!((Ice.ObjectPrxHelperBase)_defaultLocator).iceReference().getEncoding().Equals(encoding)) |
| | | 646 | | { |
| | 1 | 647 | | locatorInfo = _instance.locatorManager().get( |
| | 1 | 648 | | (Ice.LocatorPrx)_defaultLocator.ice_encodingVersion(encoding)); |
| | | 649 | | } |
| | | 650 | | else |
| | | 651 | | { |
| | 1 | 652 | | locatorInfo = _instance.locatorManager().get(_defaultLocator); |
| | | 653 | | } |
| | | 654 | | } |
| | 1 | 655 | | RouterInfo routerInfo = _instance.routerManager().get(_defaultRouter); |
| | 1 | 656 | | bool collocOptimized = defaultsAndOverrides.defaultCollocationOptimization; |
| | 1 | 657 | | bool cacheConnection = true; |
| | 1 | 658 | | Ice.EndpointSelectionType endpointSelection = defaultsAndOverrides.defaultEndpointSelection; |
| | 1 | 659 | | TimeSpan locatorCacheTimeout = defaultsAndOverrides.defaultLocatorCacheTimeout; |
| | 1 | 660 | | TimeSpan invocationTimeout = defaultsAndOverrides.defaultInvocationTimeout; |
| | 1 | 661 | | Dictionary<string, string> context = null; |
| | | 662 | | |
| | | 663 | | // |
| | | 664 | | // Override the defaults with the proxy properties if a property prefix is defined. |
| | | 665 | | // |
| | 1 | 666 | | if (propertyPrefix != null && propertyPrefix.Length > 0) |
| | | 667 | | { |
| | 1 | 668 | | Properties properties = _instance.initializationData().properties; |
| | | 669 | | |
| | 1 | 670 | | Properties.validatePropertiesWithPrefix(propertyPrefix, properties, PropertyNames.ProxyProps); |
| | | 671 | | |
| | | 672 | | string property; |
| | | 673 | | |
| | 1 | 674 | | property = propertyPrefix + ".Locator"; |
| | 1 | 675 | | Ice.LocatorPrx locator = Ice.LocatorPrxHelper.uncheckedCast(_communicator.propertyToProxy(property)); |
| | 1 | 676 | | if (locator != null) |
| | | 677 | | { |
| | 1 | 678 | | if (!((Ice.ObjectPrxHelperBase)locator).iceReference().getEncoding().Equals(encoding)) |
| | | 679 | | { |
| | 0 | 680 | | locatorInfo = _instance.locatorManager().get( |
| | 0 | 681 | | (Ice.LocatorPrx)locator.ice_encodingVersion(encoding)); |
| | | 682 | | } |
| | | 683 | | else |
| | | 684 | | { |
| | 1 | 685 | | locatorInfo = _instance.locatorManager().get(locator); |
| | | 686 | | } |
| | | 687 | | } |
| | | 688 | | |
| | 1 | 689 | | property = propertyPrefix + ".Router"; |
| | 1 | 690 | | Ice.RouterPrx router = Ice.RouterPrxHelper.uncheckedCast(_communicator.propertyToProxy(property)); |
| | 1 | 691 | | if (router != null) |
| | | 692 | | { |
| | 1 | 693 | | if (propertyPrefix.EndsWith(".Router", StringComparison.Ordinal)) |
| | | 694 | | { |
| | 0 | 695 | | string s = "`" + property + "=" + properties.getProperty(property) + |
| | 0 | 696 | | "': cannot set a router on a router; setting ignored"; |
| | 0 | 697 | | _instance.initializationData().logger.warning(s); |
| | | 698 | | } |
| | | 699 | | else |
| | | 700 | | { |
| | 1 | 701 | | routerInfo = _instance.routerManager().get(router); |
| | | 702 | | } |
| | | 703 | | } |
| | | 704 | | |
| | 1 | 705 | | property = propertyPrefix + ".CollocationOptimized"; |
| | 1 | 706 | | collocOptimized = properties.getPropertyAsIntWithDefault(property, collocOptimized ? 1 : 0) > 0; |
| | | 707 | | |
| | 1 | 708 | | property = propertyPrefix + ".ConnectionCached"; |
| | 1 | 709 | | cacheConnection = properties.getPropertyAsIntWithDefault(property, cacheConnection ? 1 : 0) > 0; |
| | | 710 | | |
| | 1 | 711 | | property = propertyPrefix + ".EndpointSelection"; |
| | 1 | 712 | | if (properties.getProperty(property).Length > 0) |
| | | 713 | | { |
| | 1 | 714 | | string type = properties.getProperty(property); |
| | 1 | 715 | | if (type == "Random") |
| | | 716 | | { |
| | 1 | 717 | | endpointSelection = Ice.EndpointSelectionType.Random; |
| | | 718 | | } |
| | 1 | 719 | | else if (type == "Ordered") |
| | | 720 | | { |
| | 1 | 721 | | endpointSelection = Ice.EndpointSelectionType.Ordered; |
| | | 722 | | } |
| | | 723 | | else |
| | | 724 | | { |
| | 0 | 725 | | throw new ParseException( |
| | 0 | 726 | | $"illegal value '{type}' in property '{property}'; expected 'Random' or 'Ordered'"); |
| | | 727 | | } |
| | | 728 | | } |
| | | 729 | | |
| | 1 | 730 | | property = propertyPrefix + ".LocatorCacheTimeout"; |
| | 1 | 731 | | locatorCacheTimeout = TimeSpan.FromSeconds( |
| | 1 | 732 | | properties.getPropertyAsIntWithDefault(property, (int)locatorCacheTimeout.TotalSeconds)); |
| | | 733 | | |
| | 1 | 734 | | property = propertyPrefix + ".InvocationTimeout"; |
| | 1 | 735 | | invocationTimeout = TimeSpan.FromMilliseconds( |
| | 1 | 736 | | properties.getPropertyAsIntWithDefault(property, (int)invocationTimeout.TotalMilliseconds)); |
| | | 737 | | |
| | 1 | 738 | | property = propertyPrefix + ".Context."; |
| | 1 | 739 | | Dictionary<string, string> contexts = properties.getPropertiesForPrefix(property); |
| | 1 | 740 | | if (contexts.Count != 0) |
| | | 741 | | { |
| | 1 | 742 | | context = new Dictionary<string, string>(); |
| | 1 | 743 | | foreach (KeyValuePair<string, string> e in contexts) |
| | | 744 | | { |
| | 1 | 745 | | context.Add(e.Key[property.Length..], e.Value); |
| | | 746 | | } |
| | | 747 | | } |
| | | 748 | | } |
| | | 749 | | |
| | | 750 | | // |
| | | 751 | | // Create new reference |
| | | 752 | | // |
| | 1 | 753 | | return new RoutableReference( |
| | 1 | 754 | | _instance, |
| | 1 | 755 | | _communicator, |
| | 1 | 756 | | ident, |
| | 1 | 757 | | facet, |
| | 1 | 758 | | mode, |
| | 1 | 759 | | compress: null, |
| | 1 | 760 | | protocol, |
| | 1 | 761 | | encoding, |
| | 1 | 762 | | endpoints, |
| | 1 | 763 | | adapterId, |
| | 1 | 764 | | locatorInfo, |
| | 1 | 765 | | routerInfo, |
| | 1 | 766 | | collocOptimized, |
| | 1 | 767 | | cacheConnection, |
| | 1 | 768 | | endpointSelection, |
| | 1 | 769 | | locatorCacheTimeout, |
| | 1 | 770 | | invocationTimeout, |
| | 1 | 771 | | context); |
| | | 772 | | } |
| | | 773 | | |
| | | 774 | | private readonly Instance _instance; |
| | | 775 | | private readonly Ice.Communicator _communicator; |
| | | 776 | | private Ice.RouterPrx _defaultRouter; |
| | | 777 | | private Ice.LocatorPrx _defaultLocator; |
| | | 778 | | } |