-
Notifications
You must be signed in to change notification settings - Fork 0
/
scheme.c
190 lines (174 loc) · 3.97 KB
/
scheme.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#pragma optimize 79
#pragma noroot
#include <Types.h>
#include "url.h"
void parse_scheme(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 | 0x20) + size) & 0x0f;
switch(h)
{
// --- begin auto-generated --
case 0x01:
// nfs
if (size == 3
&& (wp[0] | 0x2020) == 0x666e // 'nf'
&& (cp[2] | 0x20) == 0x73 // 's'
) {
c->schemeType = SCHEME_NFS;
c->portNumber = 2049;
return;
}
break;
case 0x02:
// nntp
if (size == 4
&& (wp[0] | 0x2020) == 0x6e6e // 'nn'
&& (wp[1] | 0x2020) == 0x7074 // 'tp'
) {
c->schemeType = SCHEME_NNTP;
c->portNumber = 119;
return;
}
break;
case 0x04:
// afp
if (size == 3
&& (wp[0] | 0x2020) == 0x6661 // 'af'
&& (cp[2] | 0x20) == 0x70 // 'p'
) {
c->schemeType = SCHEME_AFP;
c->portNumber = 548;
return;
}
break;
case 0x06:
// ssh
if (size == 3
&& (wp[0] | 0x2020) == 0x7373 // 'ss'
&& (cp[2] | 0x20) == 0x68 // 'h'
) {
c->schemeType = SCHEME_SSH;
c->portNumber = 22;
return;
}
// smb
if (size == 3
&& (wp[0] | 0x2020) == 0x6d73 // 'sm'
&& (cp[2] | 0x20) == 0x62 // 'b'
) {
c->schemeType = SCHEME_SMB;
c->portNumber = 445;
return;
}
break;
case 0x07:
// sftp
if (size == 4
&& (wp[0] | 0x2020) == 0x6673 // 'sf'
&& (wp[1] | 0x2020) == 0x7074 // 'tp'
) {
c->schemeType = SCHEME_SFTP;
c->portNumber = 115;
return;
}
break;
case 0x08:
// dict
if (size == 4
&& (wp[0] | 0x2020) == 0x6964 // 'di'
&& (wp[1] | 0x2020) == 0x7463 // 'ct'
) {
c->schemeType = SCHEME_DICT;
c->portNumber = 2628;
return;
}
// tftp
if (size == 4
&& (wp[0] | 0x2020) == 0x6674 // 'tf'
&& (wp[1] | 0x2020) == 0x7074 // 'tp'
) {
c->schemeType = SCHEME_TFTP;
c->portNumber = 69;
return;
}
break;
case 0x09:
// ftp
if (size == 3
&& (wp[0] | 0x2020) == 0x7466 // 'ft'
&& (cp[2] | 0x20) == 0x70 // 'p'
) {
c->schemeType = SCHEME_FTP;
c->portNumber = 21;
return;
}
break;
case 0x0a:
// file
if (size == 4
&& (wp[0] | 0x2020) == 0x6966 // 'fi'
&& (wp[1] | 0x2020) == 0x656c // 'le'
) {
c->schemeType = SCHEME_FILE;
c->portNumber = 0;
return;
}
// telnet
if (size == 6
&& (wp[0] | 0x2020) == 0x6574 // 'te'
&& (wp[1] | 0x2020) == 0x6e6c // 'ln'
&& (wp[2] | 0x2020) == 0x7465 // 'et'
) {
c->schemeType = SCHEME_TELNET;
c->portNumber = 23;
return;
}
break;
case 0x0c:
// http
if (size == 4
&& (wp[0] | 0x2020) == 0x7468 // 'ht'
&& (wp[1] | 0x2020) == 0x7074 // 'tp'
) {
c->schemeType = SCHEME_HTTP;
c->portNumber = 80;
return;
}
break;
case 0x0d:
// gopher
if (size == 6
&& (wp[0] | 0x2020) == 0x6f67 // 'go'
&& (wp[1] | 0x2020) == 0x6870 // 'ph'
&& (wp[2] | 0x2020) == 0x7265 // 'er'
) {
c->schemeType = SCHEME_GOPHER;
c->portNumber = 70;
return;
}
// https
if (size == 5
&& (wp[0] | 0x2020) == 0x7468 // 'ht'
&& (wp[1] | 0x2020) == 0x7074 // 'tp'
&& (cp[4] | 0x20) == 0x73 // 's'
) {
c->schemeType = SCHEME_HTTPS;
c->portNumber = 443;
return;
}
break;
// --- end auto-generated --
}
c->portNumber = 0;
c->schemeType = SCHEME_UNKNOWN;
}