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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "curl_setup.h"
#include "protocol.h"
#include "strcase.h"
#include "dict.h"
#include "file.h"
#include "ftp.h"
#include "gopher.h"
#include "http.h"
#include "imap.h"
#include "curl_ldap.h"
#include "mqtt.h"
#include "pop3.h"
#include "rtsp.h"
#include "smb.h"
#include "smtp.h"
#include "telnet.h"
#include "tftp.h"
#include "ws.h"
#include "vssh/ssh.h"
/* All URI schemes known to libcurl, but not necessarily implemented
* by protocol handlers. */
const struct Curl_scheme Curl_scheme_dict = {
"dict", /* scheme */
#ifdef CURL_DISABLE_DICT
ZERO_NULL,
#else
&Curl_protocol_dict,
#endif
CURLPROTO_DICT, /* protocol */
CURLPROTO_DICT, /* family */
PROTOPT_NONE | PROTOPT_NOURLQUERY, /* flags */
PORT_DICT, /* defport */
};
const struct Curl_scheme Curl_scheme_file = {
"file", /* scheme */
#ifdef CURL_DISABLE_FILE
ZERO_NULL,
#else
&Curl_protocol_file,
#endif
CURLPROTO_FILE, /* protocol */
CURLPROTO_FILE, /* family */
PROTOPT_NONETWORK | PROTOPT_NOURLQUERY, /* flags */
0 /* defport */
};
const struct Curl_scheme Curl_scheme_ftp = {
"ftp", /* scheme */
#ifdef CURL_DISABLE_FTP
ZERO_NULL,
#else
&Curl_protocol_ftp,
#endif
CURLPROTO_FTP, /* protocol */
CURLPROTO_FTP, /* family */
PROTOPT_DUAL | PROTOPT_CLOSEACTION | PROTOPT_NEEDSPWD |
PROTOPT_NOURLQUERY | PROTOPT_PROXY_AS_HTTP |
PROTOPT_WILDCARD | PROTOPT_SSL_REUSE |
PROTOPT_CONN_REUSE, /* flags */
PORT_FTP, /* defport */
};
const struct Curl_scheme Curl_scheme_ftps = {
"ftps", /* scheme */
#if defined(CURL_DISABLE_FTP) || !defined(USE_SSL)
ZERO_NULL,
#else
&Curl_protocol_ftp,
#endif
CURLPROTO_FTPS, /* protocol */
CURLPROTO_FTP, /* family */
PROTOPT_SSL | PROTOPT_DUAL | PROTOPT_CLOSEACTION |
PROTOPT_NEEDSPWD | PROTOPT_NOURLQUERY | PROTOPT_WILDCARD |
PROTOPT_CONN_REUSE, /* flags */
PORT_FTPS, /* defport */
};
const struct Curl_scheme Curl_scheme_gopher = {
"gopher", /* scheme */
#ifdef CURL_DISABLE_GOPHER
ZERO_NULL,
#else
&Curl_protocol_gopher,
#endif
CURLPROTO_GOPHER, /* protocol */
CURLPROTO_GOPHER, /* family */
PROTOPT_NONE, /* flags */
PORT_GOPHER, /* defport */
};
const struct Curl_scheme Curl_scheme_gophers = {
"gophers", /* scheme */
#if defined(CURL_DISABLE_GOPHER) || !defined(USE_SSL)
ZERO_NULL,
#else
&Curl_protocol_gophers,
#endif
CURLPROTO_GOPHERS, /* protocol */
CURLPROTO_GOPHER, /* family */
PROTOPT_SSL, /* flags */
PORT_GOPHER, /* defport */
};
const struct Curl_scheme Curl_scheme_http = {
"http", /* scheme */
#ifdef CURL_DISABLE_HTTP
ZERO_NULL,
#else
&Curl_protocol_http,
#endif
CURLPROTO_HTTP, /* protocol */
CURLPROTO_HTTP, /* family */
PROTOPT_CREDSPERREQUEST | /* flags */
PROTOPT_USERPWDCTRL | PROTOPT_CONN_REUSE,
PORT_HTTP, /* defport */
};
const struct Curl_scheme Curl_scheme_https = {
"https", /* scheme */
#if defined(CURL_DISABLE_HTTP) || !defined(USE_SSL)
ZERO_NULL,
#else
&Curl_protocol_http,
#endif
CURLPROTO_HTTPS, /* protocol */
CURLPROTO_HTTP, /* family */
PROTOPT_SSL | PROTOPT_CREDSPERREQUEST | PROTOPT_ALPN | /* flags */
PROTOPT_USERPWDCTRL | PROTOPT_CONN_REUSE |
PROTOPT_HTTP_PROXY_TUNNEL,
PORT_HTTPS, /* defport */
};
const struct Curl_scheme Curl_scheme_imap = {
"imap", /* scheme */
#ifdef CURL_DISABLE_IMAP
ZERO_NULL,
#else
&Curl_protocol_imap,
#endif
CURLPROTO_IMAP, /* protocol */
CURLPROTO_IMAP, /* family */
PROTOPT_CLOSEACTION | /* flags */
PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE |
PROTOPT_CONN_REUSE,
PORT_IMAP, /* defport */
};
const struct Curl_scheme Curl_scheme_imaps = {
"imaps", /* scheme */
#if defined(CURL_DISABLE_IMAP) || !defined(USE_SSL)
ZERO_NULL,
#else
&Curl_protocol_imap,
#endif
CURLPROTO_IMAPS, /* protocol */
CURLPROTO_IMAP, /* family */
PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */
PROTOPT_URLOPTIONS | PROTOPT_CONN_REUSE,
PORT_IMAPS, /* defport */
};
const struct Curl_scheme Curl_scheme_ldap = {
"ldap", /* scheme */
#ifdef CURL_DISABLE_LDAP
ZERO_NULL,
#else
&Curl_protocol_ldap,
#endif
CURLPROTO_LDAP, /* protocol */
CURLPROTO_LDAP, /* family */
PROTOPT_SSL_REUSE, /* flags */
PORT_LDAP, /* defport */
};
const struct Curl_scheme Curl_scheme_ldaps = {
"ldaps", /* scheme */
#if defined(CURL_DISABLE_LDAP) || !defined(HAVE_LDAP_SSL)
ZERO_NULL,
#else
&Curl_protocol_ldap,
#endif
CURLPROTO_LDAPS, /* protocol */
CURLPROTO_LDAP, /* family */
PROTOPT_SSL, /* flags */
PORT_LDAPS, /* defport */
};
const struct Curl_scheme Curl_scheme_mqtt = {
"mqtt", /* scheme */
#ifdef CURL_DISABLE_MQTT
ZERO_NULL,
#else
&Curl_protocol_mqtt,
#endif
CURLPROTO_MQTT, /* protocol */
CURLPROTO_MQTT, /* family */
PROTOPT_NONE, /* flags */
PORT_MQTT, /* defport */
};
const struct Curl_scheme Curl_scheme_mqtts = {
"mqtts", /* scheme */
#if defined(CURL_DISABLE_MQTT) || !defined(USE_SSL)
ZERO_NULL,
#else
&Curl_protocol_mqtts,
#endif
CURLPROTO_MQTTS, /* protocol */
CURLPROTO_MQTT, /* family */
PROTOPT_SSL, /* flags */
PORT_MQTTS, /* defport */
};
const struct Curl_scheme Curl_scheme_pop3 = {
"pop3", /* scheme */
#ifdef CURL_DISABLE_POP3
ZERO_NULL,
#else
&Curl_protocol_pop3,
#endif
CURLPROTO_POP3, /* protocol */
CURLPROTO_POP3, /* family */
PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */
PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE | PROTOPT_CONN_REUSE,
PORT_POP3, /* defport */
};
const struct Curl_scheme Curl_scheme_pop3s = {
"pop3s", /* scheme */
#if defined(CURL_DISABLE_POP3) || !defined(USE_SSL)
ZERO_NULL,
#else
&Curl_protocol_pop3,
#endif
CURLPROTO_POP3S, /* protocol */
CURLPROTO_POP3, /* family */
PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */
PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS | PROTOPT_CONN_REUSE,
PORT_POP3S, /* defport */
};
const struct Curl_scheme Curl_scheme_rtsp = {
"rtsp", /* scheme */
#ifdef CURL_DISABLE_RTSP
ZERO_NULL,
#else
&Curl_protocol_rtsp,
#endif
CURLPROTO_RTSP, /* protocol */
CURLPROTO_RTSP, /* family */
PROTOPT_CONN_REUSE, /* flags */
PORT_RTSP, /* defport */
};
const struct Curl_scheme Curl_scheme_sftp = {
"sftp", /* scheme */
#ifndef USE_SSH
NULL,
#else
&Curl_protocol_sftp,
#endif
CURLPROTO_SFTP, /* protocol */
CURLPROTO_SFTP, /* family */
PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */
PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE,
PORT_SSH /* defport */
};
const struct Curl_scheme Curl_scheme_scp = {
"scp", /* scheme */
#ifndef USE_SSH
NULL,
#else
&Curl_protocol_scp,
#endif
CURLPROTO_SCP, /* protocol */
CURLPROTO_SCP, /* family */
PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION | /* flags */
PROTOPT_NOURLQUERY | PROTOPT_CONN_REUSE,
PORT_SSH, /* defport */
};
const struct Curl_scheme Curl_scheme_smb = {
"smb", /* scheme */
#if defined(CURL_ENABLE_SMB) && defined(USE_CURL_NTLM_CORE)
&Curl_protocol_smb,
#else
ZERO_NULL,
#endif
CURLPROTO_SMB, /* protocol */
CURLPROTO_SMB, /* family */
PROTOPT_NONE, /* flags */
PORT_SMB, /* defport */
};
const struct Curl_scheme Curl_scheme_smbs = {
"smbs", /* scheme */
#if defined(CURL_ENABLE_SMB) && defined(USE_CURL_NTLM_CORE) && defined(USE_SSL)
&Curl_protocol_smb,
#else
ZERO_NULL,
#endif
CURLPROTO_SMBS, /* protocol */
CURLPROTO_SMB, /* family */
PROTOPT_SSL, /* flags */
PORT_SMBS, /* defport */
};
const struct Curl_scheme Curl_scheme_smtp = {
"smtp", /* scheme */
#ifdef CURL_DISABLE_SMTP
ZERO_NULL,
#else
&Curl_protocol_smtp,
#endif
CURLPROTO_SMTP, /* protocol */
CURLPROTO_SMTP, /* family */
PROTOPT_CLOSEACTION | PROTOPT_NOURLQUERY | /* flags */
PROTOPT_URLOPTIONS | PROTOPT_SSL_REUSE | PROTOPT_CONN_REUSE,
PORT_SMTP, /* defport */
};
const struct Curl_scheme Curl_scheme_smtps = {
"smtps", /* scheme */
#if defined(CURL_DISABLE_SMTP) || !defined(USE_SSL)
ZERO_NULL,
#else
&Curl_protocol_smtp,
#endif
CURLPROTO_SMTPS, /* protocol */
CURLPROTO_SMTP, /* family */
PROTOPT_CLOSEACTION | PROTOPT_SSL | /* flags */
PROTOPT_NOURLQUERY | PROTOPT_URLOPTIONS | PROTOPT_CONN_REUSE,
PORT_SMTPS, /* defport */
};
const struct Curl_scheme Curl_scheme_socks = {
"socks", /* scheme */
ZERO_NULL,
CURLPROTO_SOCKS, /* protocol */
CURLPROTO_SOCKS, /* family */
PROTOPT_NO_TRANSFER, /* flags */
PORT_SOCKS, /* defport */
};
const struct Curl_scheme Curl_scheme_socks4 = {
"socks4", /* scheme */
ZERO_NULL,
CURLPROTO_SOCKS, /* protocol */
CURLPROTO_SOCKS, /* family */
PROTOPT_NO_TRANSFER, /* flags */
PORT_SOCKS, /* defport */
};
const struct Curl_scheme Curl_scheme_socks4a = {
"socks4a", /* scheme */
ZERO_NULL,
CURLPROTO_SOCKS, /* protocol */
CURLPROTO_SOCKS, /* family */
PROTOPT_NO_TRANSFER, /* flags */
PORT_SOCKS, /* defport */
};
const struct Curl_scheme Curl_scheme_socks5 = {
"socks5", /* scheme */
ZERO_NULL,
CURLPROTO_SOCKS, /* protocol */
CURLPROTO_SOCKS, /* family */
PROTOPT_NO_TRANSFER, /* flags */
PORT_SOCKS, /* defport */
};
const struct Curl_scheme Curl_scheme_socks5h = {
"socks5h", /* scheme */
ZERO_NULL,
CURLPROTO_SOCKS, /* protocol */
CURLPROTO_SOCKS, /* family */
PROTOPT_NO_TRANSFER, /* flags */
PORT_SOCKS, /* defport */
};
const struct Curl_scheme Curl_scheme_telnet = {
"telnet", /* scheme */
#ifdef CURL_DISABLE_TELNET
ZERO_NULL,
#else
&Curl_protocol_telnet,
#endif
CURLPROTO_TELNET, /* protocol */
CURLPROTO_TELNET, /* family */
PROTOPT_NONE | PROTOPT_NOURLQUERY, /* flags */
PORT_TELNET, /* defport */
};
const struct Curl_scheme Curl_scheme_tftp = {
"tftp", /* scheme */
#ifdef CURL_DISABLE_TFTP
ZERO_NULL,
#else
&Curl_protocol_tftp,
#endif
CURLPROTO_TFTP, /* protocol */
CURLPROTO_TFTP, /* family */
PROTOPT_NOTCPPROXY | PROTOPT_NOURLQUERY, /* flags */
PORT_TFTP, /* defport */
};
const struct Curl_scheme Curl_scheme_ws = {
"ws", /* scheme */
#if defined(CURL_DISABLE_WEBSOCKETS) || defined(CURL_DISABLE_HTTP)
ZERO_NULL,
#else
&Curl_protocol_ws,
#endif
CURLPROTO_WS, /* protocol */
CURLPROTO_HTTP, /* family */
PROTOPT_CREDSPERREQUEST | /* flags */
PROTOPT_USERPWDCTRL | PROTOPT_HTTP_PROXY_TUNNEL,
PORT_HTTP /* defport */
};
const struct Curl_scheme Curl_scheme_wss = {
"wss", /* scheme */
#if defined(CURL_DISABLE_WEBSOCKETS) || defined(CURL_DISABLE_HTTP) || \
!defined(USE_SSL)
ZERO_NULL,
#else
&Curl_protocol_ws,
#endif
CURLPROTO_WSS, /* protocol */
CURLPROTO_HTTP, /* family */
PROTOPT_SSL | PROTOPT_CREDSPERREQUEST | /* flags */
PROTOPT_USERPWDCTRL | PROTOPT_HTTP_PROXY_TUNNEL,
PORT_HTTPS /* defport */
};
/* Returns a struct scheme pointer if the name is a known scheme. Check the
->run struct field for non-NULL to figure out if an implementation is
present. */
const struct Curl_scheme *Curl_getn_scheme(const char *scheme, size_t len)
{
/* table generated by schemetable.c:
1. gcc schemetable.c && ./a.out
2. check how small the table gets
3. tweak the hash algorithm, then rerun from 1
4. when the table is good enough
5. copy the table into this source code
6. make sure this function uses the same hash function that worked for
schemetable.c
*/
static const struct Curl_scheme * const all_schemes[59] = { NULL,
&Curl_scheme_pop3, NULL,
&Curl_scheme_smtps,
&Curl_scheme_socks,
&Curl_scheme_socks4,
&Curl_scheme_socks5, NULL, NULL,
&Curl_scheme_gophers,
&Curl_scheme_ws,
&Curl_scheme_sftp,
&Curl_scheme_socks4a,
&Curl_scheme_scp,
&Curl_scheme_rtsp,
&Curl_scheme_dict, NULL, NULL,
&Curl_scheme_gopher, NULL, NULL, NULL,
&Curl_scheme_wss, NULL,
&Curl_scheme_smb, NULL,
&Curl_scheme_ldap,
&Curl_scheme_ldaps,
&Curl_scheme_imap, NULL, NULL, NULL,
&Curl_scheme_imaps,
&Curl_scheme_https,
&Curl_scheme_tftp,
&Curl_scheme_telnet, NULL, NULL, NULL,
&Curl_scheme_file,
&Curl_scheme_smtp, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
&Curl_scheme_ftp,
&Curl_scheme_mqtt, NULL,
&Curl_scheme_socks5h,
&Curl_scheme_http,
&Curl_scheme_pop3s, NULL,
&Curl_scheme_mqtts, NULL,
&Curl_scheme_smbs,
&Curl_scheme_ftps,
};
if(len && (len <= 7)) {
const char *s = scheme;
size_t l = len;
const struct Curl_scheme *h;
unsigned int c = 443;
while(l) {
c <<= 5;
c += (unsigned int)Curl_raw_tolower(*s);
s++;
l--;
}
h = all_schemes[c % 59];
if(h && curl_strnequal(scheme, h->name, len) && !h->name[len])
return h;
}
return NULL;
}
const struct Curl_scheme *Curl_get_scheme(const char *scheme)
{
return Curl_getn_scheme(scheme, strlen(scheme));
}