| | 1 | | // Copyright (c) ZeroC, Inc. |
| | 2 | |
|
| | 3 | | using System.Collections.Immutable; |
| | 4 | |
|
| | 5 | | namespace IceRpc.Internal; |
| | 6 | |
|
| | 7 | | /// <summary>The Ice protocol class.</summary> |
| | 8 | | internal sealed class IceProtocol : Protocol |
| | 9 | | { |
| | 10 | | /// <summary>Gets the Ice protocol singleton.</summary> |
| 10978 | 11 | | internal static IceProtocol Instance { get; } = new(); |
| | 12 | |
|
| | 13 | | /// <summary>Checks if this absolute path is well-formed.</summary> |
| | 14 | | /// <remarks>This check is more lenient than the check performed when encoding a service address with Slice1 because |
| | 15 | | /// we want the default path (`/`) to be a valid path for all protocols. Sending a request to a null/empty identity |
| | 16 | | /// is in itself ok and will most likely result in a dispatch exception with a |
| | 17 | | /// <see cref="StatusCode.NotFound" /> status code.</remarks> |
| | 18 | | internal override void CheckPath(string uriPath) |
| 324 | 19 | | { |
| 324 | 20 | | string workingPath = uriPath[1..]; // removes leading /. |
| 324 | 21 | | int firstSlash = workingPath.IndexOf('/', StringComparison.Ordinal); |
| | 22 | |
|
| | 23 | | // We can have at most one slash in the working path. |
| 324 | 24 | | if (firstSlash != -1 && firstSlash != workingPath.LastIndexOf('/')) |
| 4 | 25 | | { |
| 4 | 26 | | throw new FormatException($"Too many slashes in path '{uriPath}'."); |
| | 27 | | } |
| 320 | 28 | | } |
| | 29 | |
|
| | 30 | | /// <summary>Checks if the service address parameters are valid. The only valid parameter is adapter-id with a |
| | 31 | | /// non-empty value.</summary> |
| | 32 | | internal override void CheckServiceAddressParams(ImmutableDictionary<string, string> serviceAddressParams) |
| 113 | 33 | | { |
| 421 | 34 | | foreach ((string name, string value) in serviceAddressParams) |
| 44 | 35 | | { |
| 44 | 36 | | if (name == "adapter-id") |
| 42 | 37 | | { |
| 42 | 38 | | if (value.Length == 0) |
| 4 | 39 | | { |
| 4 | 40 | | throw new FormatException("The value of the adapter-id parameter cannot be empty."); |
| | 41 | | } |
| 38 | 42 | | } |
| | 43 | | else |
| 2 | 44 | | { |
| 2 | 45 | | throw new FormatException($"Invalid ice service address parameter name '{name}'."); |
| | 46 | | } |
| 38 | 47 | | } |
| 107 | 48 | | } |
| | 49 | |
|
| | 50 | | private IceProtocol() |
| 9 | 51 | | : base( |
| 9 | 52 | | name: "ice", |
| 9 | 53 | | defaultPort: 4061, |
| 9 | 54 | | hasFields: false, |
| 9 | 55 | | hasFragment: true, |
| 9 | 56 | | hasPayloadContinuation: false, |
| 9 | 57 | | supportsPayloadWriterInterceptors: false, |
| 9 | 58 | | byteValue: 1) |
| 9 | 59 | | { |
| 9 | 60 | | } |
| | 61 | | } |