Skip to content

Commit

Permalink
Factor out URL parsing algorithm
Browse files Browse the repository at this point in the history
Split it out editorially since it hasn't reached the same level of
implementation as the rest of the algorithm
  • Loading branch information
dontcallmedom committed Oct 3, 2024
1 parent cd9fd6e commit b3f55e8
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 101 deletions.
6 changes: 4 additions & 2 deletions amendments.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"id": 2
}
],
"set-the-configuration": [
"set-the-configuration-algo": [
{
"description": "Set default values of the <code>RTCConfiguration</code> dictionary, aligning it with current implementations",
"pr": 2691,
Expand Down Expand Up @@ -52,7 +52,9 @@
"type": "correction",
"status": "proposed",
"id": 6
},
}
],
"validate-ice-server-algo": [
{
"description": "Use the url spec to parse ice server urls",
"pr": 2853,
Expand Down
84 changes: 42 additions & 42 deletions base-rec.html
Original file line number Diff line number Diff line change
Expand Up @@ -3498,7 +3498,7 @@ <h5 id="x4-4-1-6-set-the-configuration"><bdi class="secno">4.4.1.6 </bdi>
To <dfn data-lt="set the configuration|set a configuration" id="set-pc-configuration">set a configuration</dfn>, run the
following steps:
</p>
<ol>
<ol id="set-the-configuration-algo">
<li class="no-test-needed">
<p>
Let <var>configuration</var> be the <a data-link-type="idl" href="#dom-rtcconfiguration" class="internalDFN" id="ref-for-dom-rtcconfiguration-5"><code><code>RTCConfiguration</code></code></a>
Expand Down Expand Up @@ -3652,48 +3652,8 @@ <h5 id="x4-4-1-6-set-the-configuration"><bdi class="secno">4.4.1.6 </bdi>
</li>
<li>
<p>
For each <var>url</var> in <var>urls</var> run the
following steps:
For each <var>url</var> in <var>urls</var>, run the [=validate an ICE server URL=] algorithm on <var>url</var>.
</p>
<ol>
<li>
<p>
Parse the <var>url</var> using the generic URI syntax
defined in [<cite><a class="bibref" data-link-type="biblio" href="#bib-rfc3986" title="Uniform Resource Identifier (URI): Generic Syntax">RFC3986</a></cite>] and obtain the <var>scheme
name</var>. If the parsing based on the syntax
defined in [<cite><a class="bibref" data-link-type="biblio" href="#bib-rfc3986" title="Uniform Resource Identifier (URI): Generic Syntax">RFC3986</a></cite>] fails, <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a>
a <a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#syntaxerror"><code>SyntaxError</code></a>. If the <var>scheme name</var> is
not implemented by the browser <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a>
a <a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#notsupportederror"><code>NotSupportedError</code></a>. If <var>scheme name</var> is
<code class="scheme">turn</code> or <code class="scheme">turns</code>, and parsing the <var>url</var>
using the syntax defined in [<cite><a class="bibref" data-link-type="biblio" href="#bib-rfc7065" title="Traversal Using Relays around NAT (TURN) Uniform Resource Identifiers">RFC7065</a></cite>] fails, <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#syntaxerror"><code>SyntaxError</code></a>. If <var>scheme
name</var> is <code class="scheme">stun</code> or
<code class="scheme">stuns</code>, and parsing the
<var>url</var> using the syntax defined in
[<cite><a class="bibref" data-link-type="biblio" href="#bib-rfc7064" title="URI Scheme for the Session Traversal Utilities for NAT (STUN) Protocol">RFC7064</a></cite>] fails, <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a
<a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#syntaxerror"><code>SyntaxError</code></a>.
</p>
</li>
<li>
<p>
If <var>scheme name</var> is <code class="scheme">turn</code> or <code class="scheme">turns</code>, and either of
<var>server</var>.<a data-link-type="idl" href="#dom-rtciceserver-username" class="internalDFN" id="ref-for-dom-rtciceserver-username-2"><code><code>username</code></code></a> or
<var>server</var>.<a data-link-type="idl" href="#dom-rtciceserver-credential" class="internalDFN" id="ref-for-dom-rtciceserver-credential-4"><code><code>credential</code></code></a> are
omitted, then <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> an
<a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#invalidaccesserror"><code>InvalidAccessError</code></a>.
</p>
</li>
<li>
<p>
If <var>scheme name</var> is <code class="scheme">turn</code> or <code class="scheme">turns</code>, and
<var>server</var>.<a data-link-type="idl" href="#dom-rtciceserver-credentialtype" class="internalDFN" id="ref-for-dom-rtciceserver-credentialtype-5"><code><code>credentialType</code></code></a> is
"<a data-link-type="idl" href="#dom-rtcicecredentialtype-password" class="internalDFN" id="ref-for-dom-rtcicecredentialtype-password-5"><code><code>password</code></code></a>", and
<var>server</var>.<a data-link-type="idl" href="#dom-rtciceserver-credential" class="internalDFN" id="ref-for-dom-rtciceserver-credential-5"><code><code>credential</code></code></a> is not
a <span class="idlMemberType">DOMString</span>, then
<a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> an <a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#invalidaccesserror"><code>InvalidAccessError</code></a>.
</p>
</li>
</ol>
</li>
<li>
<p>
Expand Down Expand Up @@ -3725,6 +3685,46 @@ <h5 id="x4-4-1-6-set-the-configuration"><bdi class="secno">4.4.1.6 </bdi>
</p>
</li>
</ol>
<p>To <dfn id="validate-ice-server">validate an ICE server URL</dfn> <var>url</var>, run the following steps:</p>
<ol id="validate-ice-server-algo">
<li>
<p>
Parse the <var>url</var> using the generic URI syntax
defined in [<cite><a class="bibref" data-link-type="biblio" href="#bib-rfc3986" title="Uniform Resource Identifier (URI): Generic Syntax">RFC3986</a></cite>] and obtain the <var>scheme
name</var>. If the parsing based on the syntax
defined in [<cite><a class="bibref" data-link-type="biblio" href="#bib-rfc3986" title="Uniform Resource Identifier (URI): Generic Syntax">RFC3986</a></cite>] fails, <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a>
a <a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#syntaxerror"><code>SyntaxError</code></a>. If the <var>scheme name</var> is
not implemented by the browser <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a>
a <a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#notsupportederror"><code>NotSupportedError</code></a>. If <var>scheme name</var> is
<code class="scheme">turn</code> or <code class="scheme">turns</code>, and parsing the <var>url</var>
using the syntax defined in [<cite><a class="bibref" data-link-type="biblio" href="#bib-rfc7065" title="Traversal Using Relays around NAT (TURN) Uniform Resource Identifiers">RFC7065</a></cite>] fails, <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a <a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#syntaxerror"><code>SyntaxError</code></a>. If <var>scheme
name</var> is <code class="scheme">stun</code> or
<code class="scheme">stuns</code>, and parsing the
<var>url</var> using the syntax defined in
[<cite><a class="bibref" data-link-type="biblio" href="#bib-rfc7064" title="URI Scheme for the Session Traversal Utilities for NAT (STUN) Protocol">RFC7064</a></cite>] fails, <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> a
<a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#syntaxerror"><code>SyntaxError</code></a>.
</p>
</li>
<li>
<p>
If <var>scheme name</var> is <code class="scheme">turn</code> or <code class="scheme">turns</code>, and either of
<var>server</var>.<a data-link-type="idl" href="#dom-rtciceserver-username" class="internalDFN" id="ref-for-dom-rtciceserver-username-2"><code><code>username</code></code></a> or
<var>server</var>.<a data-link-type="idl" href="#dom-rtciceserver-credential" class="internalDFN" id="ref-for-dom-rtciceserver-credential-4"><code><code>credential</code></code></a> are
omitted, then <a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> an
<a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#invalidaccesserror"><code>InvalidAccessError</code></a>.
</p>
</li>
<li>
<p>
If <var>scheme name</var> is <code class="scheme">turn</code> or <code class="scheme">turns</code>, and
<var>server</var>.<a data-link-type="idl" href="#dom-rtciceserver-credentialtype" class="internalDFN" id="ref-for-dom-rtciceserver-credentialtype-5"><code><code>credentialType</code></code></a> is
"<a data-link-type="idl" href="#dom-rtcicecredentialtype-password" class="internalDFN" id="ref-for-dom-rtcicecredentialtype-password-5"><code><code>password</code></code></a>", and
<var>server</var>.<a data-link-type="idl" href="#dom-rtciceserver-credential" class="internalDFN" id="ref-for-dom-rtciceserver-credential-5"><code><code>credential</code></code></a> is not
a <span class="idlMemberType">DOMString</span>, then
<a data-link-type="dfn" data-type="dfn" href="https://heycam.github.io/webidl/#dfn-throw">throw</a> an <a data-link-type="idl" data-type="exception" href="https://heycam.github.io/webidl/#invalidaccesserror"><code>InvalidAccessError</code></a>.
</p>
</li>
</ol>
</section>
</section>
<section id="interface-definition">
Expand Down
108 changes: 51 additions & 57 deletions webrtc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2920,7 +2920,7 @@ <h4>
"set-pc-configuration">set a configuration</dfn> with
<var>configuration</var>, run the following steps:
</p>
<ol class=algorithm>
<ol class=algorithm id="set-the-configuration-algo">
<li class="no-test-needed">
<p>
Let <var>connection</var> be the target {{RTCPeerConnection}}
Expand Down Expand Up @@ -3047,63 +3047,8 @@ <h4>
</li>
<li>
<p>
For each <var>url</var> in <var>urls</var> run the
following steps:
For each <var>url</var> in <var>urls</var>, run the [=validate an ICE server URL=] algorithm on <var>url</var>.
</p>
<ol>
<li>
<p>Let <var>parsedURL</var> be the result of
<a data-cite="!url#concept-url-parser">parsing</a>
<var>url</var>.</p>
</li>
<li>
<p>If any of the following conditions apply, then [=exception/throw=] a
"{{SyntaxError}}" {{DOMException}}:</p>
<ul>
<li><var>parsedURL</var> is failure</li>
<li><var>parsedURL</var>'s [=url/scheme=] is neither `"stun"`,
`"stuns"`, `"turn"`, nor `"turns"`</li>
<li><var>parsedURL</var> does not have an [=url/opaque path=]</li>
<li><var>parsedURL</var>'s' [=url/fragment=] is non-null</li>
<li><var>parsedURL</var>'s' [=url/scheme=] is `"stun"` or `"stuns"`,
and <var>parsedURL</var>'s' [=url/query=] is non-null</li>
</ul>
</li>
<li>
<p>If <var>parsedURL</var>'s [=url/scheme=] is not implemented by the
user agent, then [=exception/throw=] a {{NotSupportedError}}.</p>
</li>
<li>
<p>Let <var>hostAndPortURL</var> be result of
<a data-cite="!url#concept-url-parser">parsing</a> the concatenation of
`"https://"` and <var>parsedURL</var>'s [=url/path=].</p>
</li>
<li>
<p>If <var>hostAndPortURL</var> is failure, then [=exception/throw=] a
"{{SyntaxError}}" {{DOMException}}.</p>
<p class="note">For "stun" and "stuns" schemes, this validates
[[!RFC7064]] section 3.1.<br>
For "turn" and "turns" schemes, this and the steps below validate
[[!RFC7065]] section 3.1.</p>
</li>
<li>
<p>If <var>parsedURL</var>'s [=url/query=] is non-null, run the following
sub-steps:</p>
<ol>
<li><p>TODO: validate ?transport=udp|tcp</p></li>
</ol>
</li>
<li>
<p>
If <var>parsedURL</var>'s' [=url/scheme=] is <code>"turn"</code> or
<code>"turns"</code>, and either of
<var>server</var>.{{RTCIceServer/username}} or
<var>server</var>.{{RTCIceServer/credential}} do
[=map/exist|not exist=], then [= exception/throw =] an
{{InvalidAccessError}}.
</p>
</li>
</ol>
</li>
</ol>
</li>
Expand Down Expand Up @@ -3161,6 +3106,55 @@ <h4>
</p>
</li>
</ol>
<p>To <dfn class="abstract-op">validate an ICE server URL</dfn> <var>url</var>, run the following steps:</p>
<ol id="validate-ice-server-algo" class="algorithm">
<li>
<p>Let <var>parsedURL</var> be the result of
<a data-cite="!url#concept-url-parser">parsing</a>
<var>url</var>.</p>
</li>
<li>
<p>If any of the following conditions apply, then [=exception/throw=] a
"{{SyntaxError}}" {{DOMException}}:</p>
<ul>
<li><var>parsedURL</var> is failure</li>
<li><var>parsedURL</var>'s [=url/scheme=] is neither `"stun"`,
`"stuns"`, `"turn"`, nor `"turns"`</li>
<li><var>parsedURL</var> does not have an [=url/opaque path=]</li>
<li><var>parsedURL</var>'s' [=url/fragment=] is non-null</li>
<li><var>parsedURL</var>'s' [=url/scheme=] is `"stun"` or `"stuns"`,
and <var>parsedURL</var>'s' [=url/query=] is non-null</li>
</ul>
</li>
<li>
<p>If <var>parsedURL</var>'s [=url/scheme=] is not implemented by the
user agent, then [=exception/throw=] a {{NotSupportedError}}.</p>
</li>
<li>
<p>Let <var>hostAndPortURL</var> be result of
<a data-cite="!url#concept-url-parser">parsing</a> the concatenation of
`"https://"` and <var>parsedURL</var>'s [=url/path=].</p>
</li>
<li>
<p>If <var>hostAndPortURL</var> is failure, then [=exception/throw=] a
"{{SyntaxError}}" {{DOMException}}.</p>
<p class="note">For "stun" and "stuns" schemes, this validates
[[!RFC7064]] section 3.1.<br>
For "turn" and "turns" schemes, this and the steps below validate
[[!RFC7065]] section 3.1.</p>
</li>
<li><p>TODO: validate ?transport=udp|tcp (see <a href="https://github.com/w3c/webrtc-pc/pull/2996">PR #2996</a>)</p></li>
<li>
<p>
If <var>parsedURL</var>'s' [=url/scheme=] is <code>"turn"</code> or
<code>"turns"</code>, and either of
<var>server</var>.{{RTCIceServer/username}} or
<var>server</var>.{{RTCIceServer/credential}} do
[=map/exist|not exist=], then [= exception/throw =] an
{{InvalidAccessError}}.
</p>
</li>
</ol>
</section>
</section>
<section>
Expand Down

0 comments on commit b3f55e8

Please sign in to comment.