Artifactspublic-v0

curl

master
ply4 git calls29 ms290 KiB3 cachedprotocol v2
388 lines10 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
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.
13 *
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.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24/*
25 * IDN conversions
26 */
27#include "curl_setup.h"
29#include "urldata.h"
30#include "curlx/strparse.h"
31#include "idn.h"
33#ifdef USE_LIBIDN2
34#include <idn2.h>
36#if defined(_WIN32) && defined(UNICODE)
37#define IDN2_LOOKUP(name, host, flags) \
38 idn2_lookup_u8((const uint8_t *)name, (uint8_t **)host, flags)
39#else
40#define IDN2_LOOKUP(name, host, flags) \
41 idn2_lookup_ul((const char *)(name), (char **)(host), flags)
42#endif
43#endif /* USE_LIBIDN2 */
45/* for macOS and iOS targets */
46#ifdef USE_APPLE_IDN
47#include <unicode/uidna.h>
48#include <iconv.h>
49#include <langinfo.h>
51#define MAX_HOST_LENGTH 512
53static CURLcode iconv_to_utf8(const char *in, size_t inlen,
54 char **out, size_t *outlen)
56 iconv_t cd = iconv_open("UTF-8", nl_langinfo(CODESET));
57 if(cd != (iconv_t)-1) {
58 size_t iconv_outlen = *outlen;
59 char *iconv_in = (char *)CURL_UNCONST(in);
60 size_t iconv_inlen = inlen;
61 size_t iconv_result = iconv(cd, &iconv_in, &iconv_inlen,
62 out, &iconv_outlen);
63 *outlen -= iconv_outlen;
64 iconv_close(cd);
65 if(iconv_result == (size_t)-1) {
66 /* !checksrc! disable ERRNOVAR 1 */
67 if(errno == ENOMEM)
68 return CURLE_OUT_OF_MEMORY;
69 else
70 return CURLE_URL_MALFORMAT;
71 }
73 return CURLE_OK;
74 }
75 else {
76 /* !checksrc! disable ERRNOVAR 1 */
77 if(errno == ENOMEM)
78 return CURLE_OUT_OF_MEMORY;
79 else
80 return CURLE_FAILED_INIT;
81 }
84static CURLcode mac_idn_to_ascii(const char *in, char **out)
86 size_t inlen = strlen(in);
87 if(inlen < MAX_HOST_LENGTH) {
88 char iconv_buffer[MAX_HOST_LENGTH] = { 0 };
89 char *iconv_outptr = iconv_buffer;
90 size_t iconv_outlen = sizeof(iconv_buffer);
91 CURLcode iconv_result = iconv_to_utf8(in, inlen,
92 &iconv_outptr, &iconv_outlen);
93 if(!iconv_result) {
94 UErrorCode err = U_ZERO_ERROR;
95 UIDNA *idna = uidna_openUTS46(
96 UIDNA_CHECK_BIDI | UIDNA_NONTRANSITIONAL_TO_ASCII, &err);
97 if(!U_FAILURE(err)) {
98 UIDNAInfo info = UIDNA_INFO_INITIALIZER;
99 char buffer[MAX_HOST_LENGTH] = { 0 };
100 (void)uidna_nameToASCII_UTF8(idna, iconv_buffer, (int)iconv_outlen,
101 buffer, sizeof(buffer) - 1, &info, &err);
102 uidna_close(idna);
103 if(!U_FAILURE(err) && !info.errors) {
104 *out = curlx_strdup(buffer);
105 if(*out)
106 return CURLE_OK;
107 else
108 return CURLE_OUT_OF_MEMORY;
109 }
110 }
111 }
112 else
113 return iconv_result;
114 }
115 return CURLE_URL_MALFORMAT;
118static CURLcode mac_ascii_to_idn(const char *in, char **out)
120 size_t inlen = strlen(in);
121 if(inlen < MAX_HOST_LENGTH) {
122 UErrorCode err = U_ZERO_ERROR;
123 UIDNA *idna = uidna_openUTS46(
124 UIDNA_CHECK_BIDI | UIDNA_NONTRANSITIONAL_TO_UNICODE, &err);
125 if(!U_FAILURE(err)) {
126 UIDNAInfo info = UIDNA_INFO_INITIALIZER;
127 char buffer[MAX_HOST_LENGTH] = { 0 };
128 (void)uidna_nameToUnicodeUTF8(idna, in, -1, buffer,
129 sizeof(buffer) - 1, &info, &err);
130 uidna_close(idna);
131 if(!U_FAILURE(err)) {
132 *out = curlx_strdup(buffer);
133 if(*out)
134 return CURLE_OK;
135 else
136 return CURLE_OUT_OF_MEMORY;
137 }
138 }
139 }
140 return CURLE_URL_MALFORMAT;
142#endif
144#ifdef USE_WIN32_IDN
145/* using Windows kernel32 and normaliz libraries. */
147#define IDN_MAX_LENGTH 255
149static char *idn_curlx_convert_wchar_to_UTF8(const wchar_t *str_w, int chars)
151 char *str_utf8 = NULL;
152 int bytes = WideCharToMultiByte(CP_UTF8, 0, str_w, chars, NULL, 0,
153 NULL, NULL);
154 if(bytes > 0) {
155 str_utf8 = curlx_malloc(bytes);
156 if(str_utf8) {
157 if(WideCharToMultiByte(CP_UTF8, 0, str_w, chars, str_utf8, bytes,
158 NULL, NULL) == 0) {
159 curlx_free(str_utf8);
160 return NULL;
161 }
162 }
163 }
164 return str_utf8;
167static CURLcode win32_idn_to_ascii(const char *in, char **out)
169 wchar_t in_w[IDN_MAX_LENGTH];
170 int in_w_len;
171 *out = NULL;
172 /* Returned in_w_len includes the null-terminator, which then gets
173 preserved across the calls that follow, ending up terminating
174 the buffer returned to the caller. */
175 in_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
176 in, -1, in_w, IDN_MAX_LENGTH);
177 if(in_w_len) {
178 wchar_t punycode[IDN_MAX_LENGTH];
179 int chars = IdnToAscii(0, in_w, in_w_len, punycode, IDN_MAX_LENGTH);
180 if(chars > 0) {
181 *out = idn_curlx_convert_wchar_to_UTF8(punycode, chars);
182 if(!*out)
183 return CURLE_OUT_OF_MEMORY;
184 }
185 else
186 return CURLE_URL_MALFORMAT;
187 }
188 else
189 return CURLE_URL_MALFORMAT;
191 return CURLE_OK;
194static CURLcode win32_ascii_to_idn(const char *in, char **out)
196 wchar_t in_w[IDN_MAX_LENGTH];
197 int in_w_len;
198 *out = NULL;
199 /* Returned in_w_len includes the null-terminator, which then gets
200 preserved across the calls that follow, ending up terminating
201 the buffer returned to the caller. */
202 in_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
203 in, -1, in_w, IDN_MAX_LENGTH);
204 if(in_w_len) {
205 WCHAR idn[IDN_MAX_LENGTH]; /* stores a UTF-16 string */
206 int chars = IdnToUnicode(0, in_w, in_w_len, idn, IDN_MAX_LENGTH);
207 if(chars > 0) { /* 'chars' is "the number of characters retrieved" */
208 *out = idn_curlx_convert_wchar_to_UTF8(idn, chars);
209 if(!*out)
210 return CURLE_OUT_OF_MEMORY;
211 }
212 else
213 return CURLE_URL_MALFORMAT;
214 }
215 else
216 return CURLE_URL_MALFORMAT;
218 return CURLE_OK;
221#endif /* USE_WIN32_IDN */
223/*
224 * Helpers for IDNA conversions.
225 */
226bool Curl_is_ASCII_name(const char *hostname)
228 if(hostname) {
229 struct Curl_str s;
230 s.str = hostname;
231 s.len = strlen(hostname);
232 return Curl_is_ASCII_str(&s);
233 }
234 return TRUE;
237bool Curl_is_ASCII_str(struct Curl_str *s)
239 if(s && s->len) {
240 const unsigned char *ch = (const unsigned char *)s->str;
241 size_t i;
242 for(i = 0; i < s->len; ++i) {
243 if(ch[i] & 0x80)
244 return FALSE;
245 }
246 }
247 return TRUE;
250#ifdef USE_IDN
251/*
252 * Curl_idn_decode() returns an allocated IDN decoded string if it was
253 * possible. NULL on error.
254 *
255 * CURLE_URL_MALFORMAT - the hostname could not be converted
256 * CURLE_OUT_OF_MEMORY - memory problem
257 *
258 */
259static CURLcode idn_decode(const char *input, char **output)
261 char *decoded = NULL;
262 CURLcode result = CURLE_OK;
263#ifdef USE_LIBIDN2
264 if(idn2_check_version(IDN2_VERSION)) {
265 int flags = IDN2_NFC_INPUT
266#if IDN2_VERSION_NUMBER >= 0x00140000
267 /* IDN2_NFC_INPUT: Normalize input string using normalization form C.
268 IDN2_NONTRANSITIONAL: Perform Unicode TR46 non-transitional
269 processing. */
270 | IDN2_NONTRANSITIONAL
271#endif
272 ;
273 int rc = IDN2_LOOKUP(input, &decoded, flags);
274 if(rc != IDN2_OK)
275 /* fallback to TR46 Transitional mode for better IDNA2003
276 compatibility */
277 rc = IDN2_LOOKUP(input, &decoded, IDN2_TRANSITIONAL);
278 if(rc != IDN2_OK)
279 result = CURLE_URL_MALFORMAT;
280 }
281 else
282 /* a too old libidn2 version */
283 result = CURLE_NOT_BUILT_IN;
284#elif defined(USE_WIN32_IDN)
285 result = win32_idn_to_ascii(input, &decoded);
286#elif defined(USE_APPLE_IDN)
287 result = mac_idn_to_ascii(input, &decoded);
288#endif
289 if(!result)
290 *output = decoded;
291 return result;
294static CURLcode idn_encode(const char *puny, char **output)
296 char *enc = NULL;
297#ifdef USE_LIBIDN2
298 int rc = idn2_to_unicode_8z8z(puny, &enc, 0);
299 if(rc != IDNA_SUCCESS)
300 return rc == IDNA_MALLOC_ERROR ? CURLE_OUT_OF_MEMORY : CURLE_URL_MALFORMAT;
301#elif defined(USE_WIN32_IDN)
302 CURLcode result = win32_ascii_to_idn(puny, &enc);
303 if(result)
304 return result;
305#elif defined(USE_APPLE_IDN)
306 CURLcode result = mac_ascii_to_idn(puny, &enc);
307 if(result)
308 return result;
309#endif
310 *output = enc;
311 return CURLE_OK;
314CURLcode Curl_idn_decode(const char *input, char **output)
316 char *d = NULL;
317 CURLcode result = idn_decode(input, &d);
318#ifdef USE_LIBIDN2
319 if(!result) {
320 char *c = curlx_strdup(d);
321 idn2_free(d);
322 if(c)
323 d = c;
324 else
325 result = CURLE_OUT_OF_MEMORY;
326 }
327#endif
328 if(!result) {
329 if(!d[0]) { /* ended up zero length, not acceptable */
330 result = CURLE_URL_MALFORMAT;
331 curlx_free(d);
332 }
333 else
334 *output = d;
335 }
336 return result;
339CURLcode Curl_idn_encode(const char *puny, char **output)
341 char *d = NULL;
342 CURLcode result = idn_encode(puny, &d);
343#ifdef USE_LIBIDN2
344 if(!result) {
345 char *c = curlx_strdup(d);
346 idn2_free(d);
347 if(c)
348 d = c;
349 else
350 result = CURLE_OUT_OF_MEMORY;
351 }
352#endif
353 if(!result)
354 *output = d;
355 return result;
358/*
359 * Frees data allocated by idnconvert_hostname()
360 */
361void Curl_free_idnconverted_hostname(struct hostname *host)
363 curlx_safefree(host->encalloc);
366#endif /* USE_IDN */
368/*
369 * Perform any necessary IDN conversion of hostname
370 */
371CURLcode Curl_idnconvert_hostname(struct hostname *host)
373 /* set the name we use to display the hostname */
374 host->dispname = host->name;
376#ifdef USE_IDN
377 /* Check name for non-ASCII and convert hostname if we can */
378 if(!Curl_is_ASCII_name(host->name)) {
379 char *decoded;
380 CURLcode result = Curl_idn_decode(host->name, &decoded);
381 if(result)
382 return result;
383 /* successful */
384 host->name = host->encalloc = decoded;
385 }
386#endif
387 return CURLE_OK;
Diagnostics4 git calls · 29 ms
CallStatusSizeTime029 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2003.4 KiB · hit24 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=24
git.response.bytes=3449
git.response.cache=HIT
git.response.duration_ms=24
git.fetch.wants=943a520eff5ed0c7677c8daa173a7d33759a5451
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=3449
git.pkt.payload.max=3428
git.sideband.band1.bytes=3427
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e2cbe549c67929
Request
3418ccbc…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format