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