-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ex_uri is an URI-handling library application.
- Loading branch information
0 parents
commit c7c0a17
Showing
9 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ebin/ | ||
doc/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright (c) 2010, Dev:Extend | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of Dev:Extend nor the names of its contributors may be | ||
used to endorse or promote products derived from this software without | ||
specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
An URI-handling library application. | ||
Copyright (c) 2010, Dev:Extend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-record(ex_authority, {userinfo :: string(), | ||
host :: string() | inet:ip_address(), | ||
port :: integer()}). | ||
|
||
-record(ex_uri, {scheme :: string(), | ||
authority :: #ex_authority{}, | ||
path :: [string()], | ||
q :: string(), | ||
fragment :: string()}). | ||
|
||
-record(ex_uri_ref, {authority :: #ex_authority{}, | ||
path :: [string()], | ||
q :: string(), | ||
fragment :: string()}). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
URI-reference = URI / relative-ref | ||
|
||
URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] : | ||
{Authority, Path} = _YY3, | ||
Query = case _YY4 of | ||
[[$?, Query1]] -> Query1; | ||
[] -> undefined end, | ||
Fragment = case _YY5 of | ||
[[$#, Fragment1]] -> Fragment1; | ||
[] -> undefined end, | ||
#ex_uri{scheme = _YY1, | ||
authority = Authority, | ||
path = Path, | ||
q = Query, | ||
fragment = Fragment}. | ||
|
||
relative-ref = relative-part [ "?" query ] [ "#" fragment ] : | ||
{Authority, Path} = _YY1, | ||
Query = case _YY2 of | ||
[[$?, Query1]] -> Query1; | ||
[] -> undefined end, | ||
Fragment = case _YY3 of | ||
[[$#, Fragment1]] -> Fragment1; | ||
[] -> undefined end, | ||
#ex_uri_ref{authority = Authority, | ||
path = Path, | ||
q = Query, | ||
fragment = Fragment}. | ||
|
||
relative-part = "//" authority path-abempty | ||
/ path-absolute | ||
/ path-noscheme | ||
/ path-empty : | ||
case _YY of | ||
["//", Authority, Path] -> {Authority, Path}; | ||
Path -> {undefined, Path} end. | ||
|
||
absolute-URI = scheme ":" hier-part [ "?" query ] : | ||
{Authority, Path} = _YY3, | ||
Query = case _YY4 of | ||
[[$?, Query1]] -> Query1; | ||
[] -> undefined end, | ||
#ex_uri{scheme = _YY1, authority = Authority, path = Path, q = Query}. | ||
|
||
scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) : | ||
[_YY1 | _YY2]. | ||
|
||
hier-part = "//" authority path-abempty | ||
/ path-absolute | ||
/ path-rootless | ||
/ path-empty : | ||
case _YY of | ||
["//", Authority, Path] -> {Authority, Path}; | ||
Path -> {undefined, Path} end. | ||
|
||
authority = [ userinfo "@" ] host [ ":" port ] : | ||
UserInfo = case _YY1 of | ||
[] -> undefined; | ||
[[UserInfo1, $@]] -> UserInfo1 end, | ||
Port = case _YY3 of | ||
[] -> undefined; | ||
[[$:, Port1]] -> Port1 end, | ||
#ex_authority{userinfo = UserInfo, host = _YY2, port = Port}. | ||
|
||
userinfo = *( unreserved / pct-encoded / sub-delims / ":" ) | ||
|
||
host = IP-literal / IPv4address / reg-name | ||
|
||
IP-literal = "[" ( IPv6address / IPvFuture ) "]" : | ||
_YY2. | ||
|
||
IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" ) : | ||
Version = erlang:list_to_integer(lists:flatten([_YY2]), 16), | ||
{ip, Version, lists:flatten([_YY4])}. | ||
|
||
IPv6address = 6( h16 ":" ) ls32 | ||
/ "::" 5( h16 ":" ) ls32 | ||
/ [ h16 ] "::" 4( h16 ":" ) ls32 | ||
/ [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32 | ||
/ [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32 | ||
/ [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32 | ||
/ [ *4( h16 ":" ) h16 ] "::" ls32 | ||
/ [ *5( h16 ":" ) h16 ] "::" h16 | ||
/ [ *6( h16 ":" ) h16 ] "::" : | ||
{ok, Address} = inet_parse:address(lists:flatten(_YY)), | ||
Address. | ||
|
||
h16 = 1*4HEXDIG | ||
|
||
ls32 = ( h16 ":" h16 ) / IPv4-literal | ||
|
||
IPv4address = IPv4-literal : | ||
{ok, Address} = inet_parse:address(lists:flatten(_YY)), | ||
Address. | ||
|
||
IPv4-literal = dec-octet "." dec-octet "." dec-octet "." dec-octet | ||
|
||
dec-octet = DIGIT | ||
/ %x31-39 DIGIT | ||
/ "1" 2DIGIT | ||
/ "2" %x30-34 DIGIT | ||
/ "25" %x30-35 | ||
|
||
port = *DIGIT : | ||
list_to_integer(_YY). | ||
|
||
reg-name = *( unreserved / pct-encoded / sub-delims ) | ||
|
||
path = path-abempty | ||
/ path-absolute | ||
/ path-noscheme | ||
/ path-rootless | ||
/ path-empty | ||
|
||
path-abempty = *( "/" segment ) : | ||
case _YY of | ||
[] -> _YY; | ||
[[$/, ""] | Segments] -> ["/" | [ Segment || [$/, Segment] <- Segments ]]; | ||
_YY -> ["/" | [ Segment || [$/, Segment] <- _YY ]] end. | ||
path-absolute = "/" [ segment-nz *( "/" segment ) ] : | ||
Segments = case _YY2 of | ||
[] -> _YY2; | ||
[[SegmentNz, Segments1]] -> [[$/, SegmentNz] | Segments1] end, | ||
["/" | [ Segment || [$/, Segment] <- Segments ]]. | ||
path-noscheme = segment-nz-nc *( "/" segment ) : | ||
[_YY1 | [ Segment || [$/, Segment] <- _YY2 ]]. | ||
path-rootless = segment-nz *( "/" segment ) : | ||
[_YY1 | [ Segment || [$/, Segment] <- _YY2 ]]. | ||
path-empty = 0pchar | ||
segment = *pchar | ||
segment-nz = 1*pchar | ||
segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" ) | ||
pchar = unreserved / pct-encoded / sub-delims / ":" / "@" | ||
query = *( pchar / "/" / "?" ) | ||
fragment = *( pchar / "/" / "?" ) | ||
pct-encoded = "%" HEXDIG HEXDIG : | ||
erlang:list_to_integer([_YY2, _YY3], 16). | ||
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" | ||
gen-delims = ":" / "/" / "?" / "#" / "[" / "]" / "@" | ||
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ex_uri_parser.erl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{application, ex_uri, | ||
[ | ||
{description, "An URI-handling library application"}, | ||
{vsn, "1.0.0"}, | ||
{registered, []}, | ||
{applications, [ | ||
kernel, | ||
stdlib | ||
]}, | ||
{env, []} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
%% Copyright (c) 2010, Dev:Extend | ||
%% All rights reserved. | ||
%% | ||
%% Redistribution and use in source and binary forms, with or without | ||
%% modification, are permitted provided that the following conditions are met: | ||
%% | ||
%% * Redistributions of source code must retain the above copyright notice, | ||
%% this list of conditions and the following disclaimer. | ||
%% * Redistributions in binary form must reproduce the above copyright | ||
%% notice, this list of conditions and the following disclaimer in the | ||
%% documentation and/or other materials provided with the distribution. | ||
%% * Neither the name of Dev:Extend nor the names of its contributors may be | ||
%% used to endorse or promote products derived from this software without | ||
%% specific prior written permission. | ||
%% | ||
%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
%% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
%% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
%% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
%% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
%% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
%% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
%% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
%% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
%% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
%% POSSIBILITY OF SUCH DAMAGE. | ||
|
||
-module(ex_uri). | ||
-include("ex_uri.hrl"). | ||
|
||
-export([decode/1, | ||
decode_ref/1, | ||
decode_abs/1]). | ||
|
||
%% @spec decode(string()) -> #ex_uri{} | ||
%% @doc Decode an URI. | ||
decode(String) -> | ||
ex_uri_parser:decode('URI', String). | ||
|
||
%% @spec decode_ref(string()) -> #ex_uri{} | #ex_uri_ref{} | ||
%% @doc Decode an URI reference. | ||
decode_ref(String) -> | ||
ex_uri_parser:decode('URI-reference', String). | ||
|
||
%% @spec decode_abs(string()) -> #ex_uri{} | ||
%% @doc Decode an absolute URI. | ||
decode_abs(String) -> | ||
ex_uri_parser:decode('absolute-URI', String). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-include("ex_uri.hrl"). | ||
|
||
-import(rfc4234_core, ['ALPHA'/0, 'DIGIT'/0, 'HEXDIG'/0]). |