1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 * SPDX-License-Identifier: curl
23 ***************************************************************************/
25 #include <curl/curl.h>
28 * Use this tool to generate an updated table for the Curl_getn_scheme_handler
37 static const struct detail scheme[] = {
38 {"dict", "#ifndef CURL_DISABLE_DICT" },
39 {"file", "#ifndef CURL_DISABLE_FILE" },
40 {"ftp", "#ifndef CURL_DISABLE_FTP" },
41 {"ftps", "#if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)" },
42 {"gopher", "#ifndef CURL_DISABLE_GOPHER" },
43 {"gophers", "#if defined(USE_SSL) && !defined(CURL_DISABLE_GOPHER)" },
44 {"http", "#ifndef CURL_DISABLE_HTTP" },
45 {"https", "#if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)" },
46 {"imap", "#ifndef CURL_DISABLE_IMAP" },
47 {"imaps", "#if defined(USE_SSL) && !defined(CURL_DISABLE_IMAP)" },
48 {"ldap", "#ifndef CURL_DISABLE_LDAP" },
49 {"ldaps", "#if !defined(CURL_DISABLE_LDAP) && \\\n"
50 " !defined(CURL_DISABLE_LDAPS) && \\\n"
51 " ((defined(USE_OPENLDAP) && defined(USE_SSL)) || \\\n"
52 " (!defined(USE_OPENLDAP) && defined(HAVE_LDAP_SSL)))" },
53 {"mqtt", "#ifndef CURL_DISABLE_MQTT" },
54 {"pop3", "#ifndef CURL_DISABLE_POP3" },
55 {"pop3s", "#if defined(USE_SSL) && !defined(CURL_DISABLE_POP3)" },
56 {"rtmp", "#ifdef USE_LIBRTMP" },
57 {"rtmpt", "#ifdef USE_LIBRTMP" },
58 {"rtmpe", "#ifdef USE_LIBRTMP" },
59 {"rtmpte", "#ifdef USE_LIBRTMP" },
60 {"rtmps", "#ifdef USE_LIBRTMP" },
61 {"rtmpts", "#ifdef USE_LIBRTMP" },
62 {"rtsp", "#ifndef CURL_DISABLE_RTSP" },
63 {"scp", "#if defined(USE_SSH) && !defined(USE_WOLFSSH)" },
64 {"sftp", "#if defined(USE_SSH)" },
65 {"smb", "#if !defined(CURL_DISABLE_SMB) && defined(USE_CURL_NTLM_CORE) && \\\n"
66 " (SIZEOF_CURL_OFF_T > 4)" },
67 {"smbs", "#if defined(USE_SSL) && !defined(CURL_DISABLE_SMB) && \\\n"
68 " defined(USE_CURL_NTLM_CORE) && (SIZEOF_CURL_OFF_T > 4)" },
69 {"smtp", "#ifndef CURL_DISABLE_SMTP" },
70 {"smtps", "#if defined(USE_SSL) && !defined(CURL_DISABLE_SMTP)" },
71 {"telnet", "#ifndef CURL_DISABLE_TELNET" },
72 {"tftp", "#ifndef CURL_DISABLE_TFTP" },
73 {"ws", "#if defined(USE_WEBSOCKETS) && !defined(CURL_DISABLE_HTTP)" },
74 {"wss", "#if defined(USE_WEBSOCKETS) && \\\n"
75 " defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)" },
79 unsigned int calc(const char *s, int add, int shift)
91 unsigned int num[100];
94 static void showtable(int try, int init, int shift)
98 for(i = 0; scheme[i].n; ++i)
99 num[i] = calc(scheme[i].n, init, shift);
100 for(i = 0; scheme[i].n; ++i)
101 ix[i] = num[i] % try;
103 " unsigned int c = %d\n"
106 " c += Curl_raw_tolower(*s);\n"
110 "*/\n", init, shift);
112 printf(" static const struct Curl_handler * const protocols[%d] = {", try);
115 for(i=0; i < try; i++) {
118 for(j=0; scheme[j].n; j++) {
121 printf("%s\n", scheme[j].ifdef);
122 printf(" &Curl_handler_%s,\n", scheme[j].n);
123 printf("#else\n NULL,\n");
131 if(!nulls || (nulls>10)) {
135 printf(" NULL,", nulls);
151 for(shift = 0; shift < 8; shift++) {
152 for(add = 0; add < 999; add++) {
153 for(i = 0; scheme[i].n; ++i) {
154 unsigned int v = calc(scheme[i].n, add, shift);
157 for(j=0; j < i; j++) {
161 printf("NOPE: %u is a dupe (%s and %s)\n",
162 v, scheme[i], scheme[j]);
173 for(i = 0; scheme[i].n; ++i) {
174 printf("%u - %s\n", num[i], scheme[i].n);
177 /* try different remainders to find smallest possible table */
178 for(try = 28; try < 199; try++) {
180 for(i = 0; scheme[i].n; ++i) {
181 ix[i] = num[i] % try;
183 /* check for dupes */
184 for(i = 0; scheme[i].n && good; ++i) {
186 for(j=0; j < i; j++) {
188 /* printf("NOPE, try %u causes dupes (%d and %d)\n", try, j, i); */
206 showtable(besttry, bestadd, bestshift);