Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,67 @@
with Ada.Text_IO;
with AWS.URL;
with AWS.Parameters;
with AWS.Containers.Tables;
procedure URL_Parser is
procedure Parse (URL : in String) is
use AWS.URL, Ada.Text_IO;
use AWS.Containers.Tables;
procedure Put_Cond (Item : in String;
Value : in String;
When_Not : in String := "") is
begin
if Value /= When_Not then
Put (" "); Put (Item); Put_Line (Value);
end if;
end Put_Cond;
Obj : Object;
List : Table_Type;
begin
Put_Line ("Parsing " & URL);
Obj := Parse (URL);
List := Table_Type (AWS.Parameters.List'(AWS.URL.Parameters (Obj)));
Put_Cond ("Scheme: ", Protocol_Name (Obj));
Put_Cond ("Domain: ", Host (Obj));
Put_Cond ("Port: ", Port (Obj), When_Not => "0");
Put_Cond ("Path: ", Path (Obj));
Put_Cond ("File: ", File (Obj));
Put_Cond ("Query: ", Query (Obj));
Put_Cond ("Fragment: ", Fragment (Obj));
Put_Cond ("User: ", User (Obj));
Put_Cond ("Password: ", Password (Obj));
if List.Count /= 0 then
Put_Line (" Parameters:");
end if;
for Index in 1 .. List.Count loop
Put (" "); Put (Get_Name (List, N => Index));
Put (" "); Put ("'" & Get_Value (List, N => Index) & "'");
New_Line;
end loop;
New_Line;
end Parse;
begin
Parse ("foo://example.com:8042/over/there?name=ferret#nose");
Parse ("urn:example:animal:ferret:nose");
Parse ("jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true");
Parse ("ftp://ftp.is.co.za/rfc/rfc1808.txt");
Parse ("http://www.ietf.org/rfc/rfc2396.txt#header1");
Parse ("ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two");
Parse ("mailto:John.Doe@example.com");
Parse ("news:comp.infosystems.www.servers.unix");
Parse ("tel:+1-816-555-1212");
Parse ("telnet://192.0.2.16:80/");
Parse ("urn:oasis:names:specification:docbook:dtd:xml:4.1.2");
Parse ("ssh://alice@example.com");
Parse ("https://bob:pass@example.com/place");
Parse ("http://example.com/?a=1&b=2+2&c=3&c=4&d=%65%6e%63%6F%64%65%64");
end URL_Parser;

View file

@ -0,0 +1,150 @@
#include <iostream>
#include <string>
#include <vector>
// Parser of a well-formed URL
class Parser {
public:
Parser(const std::string& url) : url(url) {
parse();
print();
}
void parse() {
// Find the Scheme
size_t scheme_end = url.find(":");
scheme = url.substr(0, scheme_end);
scheme_end += 1; // Skip over ":"
// Complete the parsing of URL's not containing "://"
const size_t double_slash = url.find("//");
if ( double_slash == std::string::npos ) {
path = url.substr(scheme_end);
return;
}
if ( double_slash != scheme_end ) {
const size_t question_mark = url.find("?", scheme_end);
path = url.substr(scheme_end, question_mark - scheme_end);
const size_t hash = url.find("#", question_mark + 1);
if ( hash == std::string::npos ) {
query = url.substr(question_mark + 1);
} else {
query = url.substr(question_mark + 1, hash - question_mark - 1);
fragment = url.substr(hash + 1);
}
return;
}
scheme_end += 2; // Skip over "//"
// Find Username and Password
const size_t at_symbol = url.find("@", scheme_end);
if ( at_symbol != std::string::npos ) {
const size_t colon = url.find(":", scheme_end);
if ( colon == std::string::npos ) {
username = url.substr(scheme_end, at_symbol - scheme_end);
} else {
username = url.substr(scheme_end, colon - scheme_end);
password = url.substr(colon + 1, at_symbol - colon - 1);
}
scheme_end = at_symbol + 1;
}
// Find Domain and Port
const size_t domain_end = url.find("/", scheme_end);
const size_t closing_bracket = url.find("]", scheme_end);
if ( closing_bracket != std::string::npos ) {
domain = url.substr(scheme_end, domain_end - scheme_end);
} else {
const size_t colon = url.find(":", scheme_end);
if ( colon == std::string::npos ) {
domain = url.substr(scheme_end, domain_end - scheme_end);
} else {
domain = url.substr(scheme_end, colon - scheme_end);
port = url.substr(colon + 1, domain_end - colon - 1);
}
}
if ( domain_end == std::string::npos ) {
return;
}
// Find Path
const size_t question_mark = url.find("?", domain_end);
const size_t hash = url.find("#", domain_end);
if ( hash == std::string::npos ) {
path = url.substr(domain_end, question_mark - domain_end);
} else {
if ( hash < question_mark ) {
path = url.substr(domain_end, hash - domain_end);
} else {
path = url.substr(domain_end, question_mark - domain_end);
}
}
const size_t path_end = ( hash < question_mark ) ? hash: question_mark;
if ( path_end == std::string::npos ) {
return;
}
// Find Query and Fragmant
const size_t query_end = url.find("#", path_end);
if ( question_mark == std::string::npos ) {
fragment = url.substr(query_end + 1);
} else {
query = url.substr(question_mark + 1, query_end - question_mark - 1);
if ( query_end != std::string::npos ) {
fragment = url.substr(query_end + 1);
}
}
}
private:
void print() const {
if ( ! url.empty() ) { std::cout << "URL = " << url << std::endl; }
if ( ! scheme.empty() ) { std::cout << "Scheme = " << scheme << std::endl; }
if ( ! username.empty() ) { std::cout << "Username = " << username << std::endl; }
if ( ! password.empty() ) { std::cout << "Password = " << password << std::endl; }
if ( ! domain.empty() ) { std::cout << "Domain = " << domain << std::endl; }
if ( ! port.empty() ) { std::cout << "Port = " << port << std::endl; }
if ( ! path.empty() ) { std::cout << "Path = " << path << std::endl; }
if ( ! query.empty() ) { std::cout << "Query = " << query << std::endl; }
if ( ! fragment.empty() ) { std::cout << "Fragment = " << fragment << std::endl; }
std::cout << std::endl;
}
std::string url;
std::string scheme;
std::string domain;
std::string port;
std::string username;
std::string password;
std::string path;
std::string query;
std::string fragment;
};
int main() {
const std::vector<std::string> urls = {
"foo://example.com:8042/over/there?name=ferret#nose",
"urn:example:animal:ferret:nose",
"jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true",
"ftp://ftp.is.co.za/rfc/rfc1808.txt",
"http://www.ietf.org/rfc/rfc2396.txt#header1",
"ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two",
"mailto:John.Doe@example.com",
"news:comp.infosystems.www.servers.unix",
"tel:+1-816-555-1212",
"telnet://192.0.2.16:80/",
"urn:oasis:names:specification:docbook:dtd:xml:4.1.2",
"ssh://alice@example.com",
"https://bob:pass@example.com/place",
"http://example.com/?a=1&b=2+2&c=3&c=4&d=\%65\%6e\%63\%6F\%64\%65\%64"
};
for ( const std::string& url : urls ) {
Parser parser(url);
}
}

View file

@ -0,0 +1,181 @@
Type URL
scheme As String * 16
username As String * 64
host As String * 64
port As Uinteger
path As String * 128
query As String * 128
frag As String * 64
End Type
Function getDefaultPort(scheme As String) As Uinteger
Select Case Lcase(scheme)
Case "http" : Return 80
Case "https": Return 443
Case "ftp" : Return 21
Case "ssh" : Return 22
Case "ldap" : Return 389
Case "news" : Return 119
Case Else : Return 0
End Select
End Function
Function uri_unescape(s As String) As String
Dim As String result = ""
Dim hex_ As String * 2
Dim As Integer val_, i = 1
While i <= Len(s)
If Mid(s, i, 1) = "%" And i + 2 <= Len(s) Then
hex_ = Mid(s, i + 1, 2)
val_ = Val("&h" + hex_)
result &= Chr(val_)
i += 3
Else
result &= Mid(s, i, 1)
i += 1
End If
Wend
Return result
End Function
Sub parse_uri(u As String, Byref uri As URL)
Dim posic As Integer
Dim hasIPv6 As Boolean = False
' Reset
uri.scheme = "": uri.host = "": uri.port = 0
uri.path = "": uri.query = "": uri.frag = ""
' Special case jdbc:mysql://
If Instr(u, "jdbc:mysql://") = 1 Then
uri.scheme = "jdbc"
posic = Instr(u, "?")
If posic > 0 Then
uri.path = Mid(u, 13, posic - 13)
uri.query = Mid(u, posic + 1)
Else
uri.path = Mid(u, 13)
End If
Return
End If
' Scheme normal
posic = Instr(u, "://")
If posic > 0 Then
uri.scheme = Left(u, posic - 1)
u = Mid(u, posic + 3)
' Authority up to "/" or end
posic = Instr(u, "/")
Dim authority As String = ""
If posic > 0 Then
authority = Left(u, posic - 1)
u = Mid(u, posic)
Else
authority = u
u = ""
End If
' Parse authority: [user:pass@]host[:port]
If Len(authority) > 0 Then
' Remove user:pass@
Dim atPos As Integer = Instrrev(authority, "@")
If atPos > 0 Then
Dim userpass As String = Left(authority, atPos - 1)
authority = Mid(authority, atPos + 1)
' user:pass -> just username for simplicity
posic = Instr(userpass, ":")
If posic > 0 Then
uri.username = Left(userpass, posic - 1)
Else
uri.username = userpass
End If
End If
' IPv6 [host]
If Left(authority, 1) = "[" Then
hasIPv6 = True
posic = Instr(authority, "]")
If posic > 0 Then
uri.host = Left(authority, posic)
Dim restPort As String = Mid(authority, posic + 1)
If Left(restPort, 1) = ":" Then uri.port = Val(Mid(restPort, 2))
End If
Else
' host:port normal
posic = Instrrev(authority, ":")
If posic > 0 And posic < Len(authority) Then
uri.host = Left(authority, posic - 1)
uri.port = Val(Mid(authority, posic + 1))
Else
uri.host = authority
End If
End If
End If
Else
' WITHOUT "/" -> scheme:path
posic = Instr(u, ":")
If posic > 0 Then
uri.scheme = Left(u, posic - 1)
u = Mid(u, posic + 1)
End If
End If
'ParsePath:
If uri.port = 0 Then uri.port = getDefaultPort(uri.scheme)
' Path/query/frag
posic = Instr(u, "?")
If posic > 0 Then
uri.path = Left(u, posic - 1)
Dim qfrag As String = Mid(u, posic + 1)
posic = Instr(qfrag, "#")
If posic > 0 Then
uri.query = Left(qfrag, posic - 1)
uri.frag = Mid(qfrag, posic + 1)
Else
uri.query = qfrag
End If
Else
posic = Instr(u, "#")
If posic > 0 Then
uri.path = Left(u, posic - 1)
uri.frag = Mid(u, posic + 1)
Else
uri.path = u
End If
End If
End Sub
' Test data
Dim As String uris(13)
uris(0) = "foo://example.com:8042/over/there?name=ferret#nose"
uris(1) = "urn:example:animal:ferret:nose"
uris(2) = "jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true"
uris(3) = "ftp://ftp.is.co.za/rfc/rfc1808.txt"
uris(4) = "http://www.ietf.org/rfc/rfc2396.txt#header1"
uris(5) = "ldap://[2001:db8::7]/c=GB?objectClass?one"
uris(6) = "mailto:John.Doe@example.com"
uris(7) = "news:comp.infosystems.www.servers.unix"
uris(8) = "tel:+1-816-555-1212"
uris(9) = "telnet://192.0.2.16:80/"
uris(10) = "urn:oasis:names:specification:docbook:dtd:xml:4.1.2"
uris(11) = "ssh://alice@example.com"
uris(12) = "https://bob:pass@example.com/place"
uris(13) = "http://example.com/?a=1&b=2+2&c=3&c=4&d=%65%6e%63%6f%64%65%64"
Dim u As URL
For i As Integer = 0 To Ubound(uris)
Print "URL: " & uris(i)
parse_uri(uris(i), u)
Print " scheme: " & Trim(u.scheme)
If Trim(u.host) <> "" Then Print " host: " & uri_unescape(Trim(u.host))
If u.port > 0 Then Print " port: " & u.port
Print " path: " & uri_unescape(Trim(u.path))
If Trim(u.query) <> "" Then Print " query: " & uri_unescape(Trim(u.query))
If Trim(u.frag) <> "" Then Print "fragment: " & uri_unescape(Trim(u.frag))
Print
Next
Sleep

View file

@ -0,0 +1,43 @@
function Get-ParsedUrl
{
[CmdletBinding()]
[OutputType([PSCustomObject])]
Param
(
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[System.Uri]
$InputObject
)
Process
{
foreach ($url in $InputObject)
{
$url | Select-Object -Property Scheme,
@{Name="Domain"; Expression={$_.Host}},
Port,
@{Name="Path" ; Expression={$_.LocalPath}},
Query,
Fragment,
AbsolutePath,
AbsoluteUri,
Authority,
HostNameType,
IsDefaultPort,
IsFile,
IsLoopback,
PathAndQuery,
Segments,
IsUnc,
OriginalString,
DnsSafeHost,
IdnHost,
IsAbsoluteUri,
UserEscaped,
UserInfo
}
}
}

View file

@ -0,0 +1,17 @@
[string[]]$urls = @'
foo://example.com:8042/over/there?name=ferret#nose
urn:example:animal:ferret:nose
jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true
ftp://ftp.is.co.za/rfc/rfc1808.txt
http://www.ietf.org/rfc/rfc2396.txt#header1
ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two
mailto:John.Doe@example.com
news:comp.infosystems.www.servers.unix
tel:+1-816-555-1212
telnet://192.0.2.16:80/
urn:oasis:names:specification:docbook:dtd:xml:4.1.2
'@ -split [Environment]::NewLine
$parsedUrls = $urls | Get-ParsedUrl
$parsedUrls | Select-Object -Property Scheme, Port, Domain, Path, Query, Fragment | Format-Table

View file

@ -0,0 +1,96 @@
Function parse_url(url)
parse_url = "URL: " & url
If InStr(url,"//") Then
'parse the scheme
scheme = Split(url,"//")
parse_url = parse_url & vbcrlf & "Scheme: " & Mid(scheme(0),1,Len(scheme(0))-1)
'parse the domain
domain = Split(scheme(1),"/")
'check if the domain includes a username, password, and port
If InStr(domain(0),"@") Then
cred = Split(domain(0),"@")
If InStr(cred(0),".") Then
username = Mid(cred(0),1,InStr(1,cred(0),".")-1)
password = Mid(cred(0),InStr(1,cred(0),".")+1,Len(cred(0))-InStr(1,cred(0),"."))
ElseIf InStr(cred(0),":") Then
username = Mid(cred(0),1,InStr(1,cred(0),":")-1)
password = Mid(cred(0),InStr(1,cred(0),":")+1,Len(cred(0))-InStr(1,cred(0),":"))
End If
parse_url = parse_url & vbcrlf & "Username: " & username & vbCrLf &_
"Password: " & password
'check if the domain have a port
If InStr(cred(1),":") Then
host = Mid(cred(1),1,InStr(1,cred(1),":")-1)
port = Mid(cred(1),InStr(1,cred(1),":")+1,Len(cred(1))-InStr(1,cred(1),":"))
parse_url = parse_url & vbCrLf & "Domain: " & host & vbCrLf & "Port: " & port
Else
parse_url = parse_url & vbCrLf & "Domain: " & cred(1)
End If
ElseIf InStr(domain(0),":") And Instr(domain(0),"[") = False And Instr(domain(0),"]") = False Then
host = Mid(domain(0),1,InStr(1,domain(0),":")-1)
port = Mid(domain(0),InStr(1,domain(0),":")+1,Len(domain(0))-InStr(1,domain(0),":"))
parse_url = parse_url & vbCrLf & "Domain: " & host & vbCrLf & "Port: " & port
ElseIf Instr(domain(0),"[") And Instr(domain(0),"]:") Then
host = Mid(domain(0),1,InStr(1,domain(0),"]"))
port = Mid(domain(0),InStr(1,domain(0),"]")+2,Len(domain(0))-(InStr(1,domain(0),"]")+1))
parse_url = parse_url & vbCrLf & "Domain: " & host & vbCrLf & "Port: " & port
Else
parse_url = parse_url & vbCrLf & "Domain: " & domain(0)
End If
'parse the path if exist
If UBound(domain) > 0 Then
For i = 1 To UBound(domain)
If i < UBound(domain) Then
path = path & domain(i) & "/"
ElseIf InStr(domain(i),"?") Then
path = path & Mid(domain(i),1,InStr(1,domain(i),"?")-1)
If InStr(domain(i),"#") Then
query = Mid(domain(i),InStr(1,domain(i),"?")+1,InStr(1,domain(i),"#")-InStr(1,domain(i),"?")-1)
fragment = Mid(domain(i),InStr(1,domain(i),"#")+1,Len(domain(i))-InStr(1,domain(i),"#"))
path = path & vbcrlf & "Query: " & query & vbCrLf & "Fragment: " & fragment
Else
query = Mid(domain(i),InStr(1,domain(i),"?")+1,Len(domain(i))-InStr(1,domain(i),"?"))
path = path & vbcrlf & "Query: " & query
End If
ElseIf InStr(domain(i),"#") Then
fragment = Mid(domain(i),InStr(1,domain(i),"#")+1,Len(domain(i))-InStr(1,domain(i),"#"))
path = path & Mid(domain(i),1,InStr(1,domain(i),"#")-1) & vbCrLf &_
"Fragment: " & fragment
Else
path = path & domain(i)
End If
Next
parse_url = parse_url & vbCrLf & "Path: " & path
End If
ElseIf InStr(url,":") Then
scheme = Mid(url,1,InStr(1,url,":")-1)
path = Mid(url,InStr(1,url,":")+1,Len(url)-InStr(1,url,":"))
parse_url = parse_url & vbcrlf & "Scheme: " & scheme & vbCrLf & "Path: " & path
Else
parse_url = parse_url & vbcrlf & "Invalid!!!"
End If
End Function
'test the convoluted function :-(
WScript.StdOut.WriteLine parse_url("foo://example.com:8042/over/there?name=ferret#nose")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("jdbc:mysql://test_user:ouupppssss@localhost:3306/sakila?profileSQL=true")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("ftp://ftp.is.co.za/rfc/rfc1808.txt")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("http://www.ietf.org/rfc/rfc2396.txt#header1")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("ldap://[2001:db8::7]/c=GB?objectClass=one&objectClass=two")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("mailto:John.Doe@example.com")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("news:comp.infosystems.www.servers.unix")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("tel:+1-816-555-1212")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("telnet://192.0.2.16:80/")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("urn:oasis:names:specification:docbook:dtd:xml:4.1.2")
WScript.StdOut.WriteLine "-------------------------------"
WScript.StdOut.WriteLine parse_url("this code is messy, long, and needs a makeover!!!")