re org code

This commit is contained in:
Kelvin Sherlock 2012-04-15 21:48:58 -04:00
parent fc873a29b4
commit 340846cd57

154
url.c
View File

@ -21,6 +21,8 @@ enum {
};
extern void parse_scheme(const char *cp, unsigned size, URLComponents *c);
/*
* scheme://username:password@domain:port/path;parms?query_string#fragment_id
*
@ -84,158 +86,6 @@ int URLComponentGet(const char *url, URLComponents *components, int type, char *
}
static void parseScheme(const char *cp, unsigned size, URLComponents *c)
{
unsigned *wp;
unsigned h;
if (!c) return;
if (!cp || !size)
{
c->portNumber = 0;
c->schemeType = SCHEME_NONE;
return;
}
wp = (unsigned *)cp;
h = (*cp ^ size) & 0x0f;
switch(h)
{
// --- begin auto-generated --
case 0:
// ssh
if (size == 3
&& (wp[0] | 0x2020) == 'ss'
&& (cp[2] | 0x20) == 'h'
)
{
c->schemeType = SCHEME_SSH;
c->portNumber = 22;
return;
}
break;
case 1:
// gopher
if (size == 6
&& (wp[0] | 0x2020) == 'og'
&& (wp[1] | 0x2020) == 'hp'
&& (wp[2] | 0x2020) == 're'
)
{
c->schemeType = SCHEME_GOPHER;
c->portNumber = 70;
return;
}
break;
case 2:
// file, telnet, afp
if (size == 4
&& (wp[0] | 0x2020) == 'if'
&& (wp[1] | 0x2020) == 'el'
)
{
c->schemeType = SCHEME_FILE;
c->portNumber = 0;
return;
}
if (size == 6
&& (wp[0] | 0x2020) == 'et'
&& (wp[1] | 0x2020) == 'nl'
&& (wp[2] | 0x2020) == 'te'
)
{
c->schemeType = SCHEME_TELNET;
c->portNumber = 23;
return;
}
if (size == 3
&& (wp[0] | 0x2020) == 'fa'
&& (cp[2] | 0x20) == 'p'
)
{
c->schemeType = SCHEME_AFP;
c->portNumber = 548;
return;
}
break;
case 5:
// ftp
if (size == 3
&& (wp[0] | 0x2020) == 'tf'
&& (cp[2] | 0x20) == 'p'
)
{
c->schemeType = SCHEME_FTP;
c->portNumber = 21;
return;
}
break;
case 7:
// sftp
if (size == 4
&& (wp[0] | 0x2020) == 'fs'
&& (wp[1] | 0x2020) == 'pt'
)
{
c->schemeType = SCHEME_SFTP;
c->portNumber = 115;
return;
}
break;
case 10:
// nntp
if (size == 4
&& (wp[0] | 0x2020) == 'nn'
&& (wp[1] | 0x2020) == 'pt'
)
{
c->schemeType = SCHEME_NNTP;
c->portNumber = 119;
return;
}
break;
case 12:
// http
if (size == 4
&& (wp[0] | 0x2020) == 'th'
&& (wp[1] | 0x2020) == 'pt'
)
{
c->schemeType = SCHEME_HTTP;
c->portNumber = 80;
return;
}
break;
case 13:
// https, nfs
if (size == 5
&& (wp[0] | 0x2020) == 'th'
&& (wp[1] | 0x2020) == 'pt'
&& (cp[4] | 0x20) == 's'
)
{
c->schemeType = SCHEME_HTTPS;
c->portNumber = 443;
return;
}
if (size == 3
&& (wp[0] | 0x2020) == 'fn'
&& (cp[2] | 0x20) == 's'
)
{
c->schemeType = SCHEME_NFS;
c->portNumber = 2049;
return;
}
break;
// --- end auto-generated --
}
c->portNumber = 0;
c->schemeType = SCHEME_UNKNOWN;
}
int ParseURL(const char *url, int length, struct URLComponents *components)