master
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#include "curl_setup.h"
26#include "urldata.h"
27#include "api.h"
28#include "curl_threads.h"
29#include "multiif.h"
30#include "vtls/vtls_scache.h"
32typedef char mapi_fn_ids_fit_uint8[
33 (CURL_MAPI_FN_LAST <= CURL_CBAPI_FN_START) ? 1 : -1];
34typedef char cbapi_fn_ids_fit_uint8[
35 ((CURL_CBAPI_FN_LAST - 1) <= UINT8_MAX) ? 1 : -1];
36typedef char mapi_depth_fits_uint8[
37 (CURL_MAPI_MAX_RECURSION <= UINT8_MAX) ? 1 : -1];
39struct Curl_eapi_fn_props {
40 Curl_eapi_fn fn;
41 uint8_t data_is_killed; /* easy handle is killed in call */
42 uint8_t recurse; /* may be called when another call is in progress */
43 uint8_t readonly; /* call is not modifying easy handle */
44 uint8_t no_scache_lock; /* may not be called with easy's vtls_scache
45 locked by current thread */
46};
48static const struct Curl_eapi_fn_props eapi_fn_props[CURL_EAPI_FN_LAST] = {
49 /* function kill rec RO !sc */
50 { CURL_EAPI_FN_easy_cleanup, 1, 0, 0, 0 },
51 { CURL_EAPI_FN_easy_duphandle, 0, 1, 1, 0 },
52 { CURL_EAPI_FN_easy_getinfo, 0, 1, 1, 0 },
53 { CURL_EAPI_FN_easy_header, 0, 1, 1, 0 },
54 { CURL_EAPI_FN_easy_nextheader, 0, 1, 1, 0 },
55 { CURL_EAPI_FN_easy_pause, 0, 1, 0, 0 },
56 { CURL_EAPI_FN_easy_perform_ev, 0, 0, 0, 1 },
57 { CURL_EAPI_FN_easy_perform, 0, 0, 0, 1 },
58 { CURL_EAPI_FN_easy_recv, 0, 0, 0, 1 },
59 { CURL_EAPI_FN_easy_reset, 0, 0, 0, 0 },
60 { CURL_EAPI_FN_easy_send, 0, 0, 0, 1 },
61 { CURL_EAPI_FN_easy_setopt, 0, 1, 0, 0 },
62 { CURL_EAPI_FN_easy_ssls_export, 0, 0, 0, 1 },
63 { CURL_EAPI_FN_easy_ssls_import, 0, 0, 0, 1 },
64 { CURL_EAPI_FN_easy_upkeep, 0, 0, 0, 1 },
65 { CURL_EAPI_FN_ws_recv, 0, 1, 0, 1 },
66 { CURL_EAPI_FN_ws_send, 0, 1, 0, 1 },
67 { CURL_EAPI_FN_ws_start_frame, 0, 1, 0, 0 },
68};
70struct Curl_mapi_fn_props {
71 Curl_mapi_fn fn;
72 uint8_t multi_is_killed; /* multi handle is killed during call */
73 uint8_t recurse; /* may be called when another call is in progress */
74 uint8_t allow_ntfy_cb; /* may be called during a notify callback */
75 uint8_t no_scache_lock; /* may not be called with multi's vtls_scache
76 locked by current thread */
77};
79static const struct Curl_mapi_fn_props mapi_fn_props[CURL_MAPI_FN_LAST] = {
80 /* function kill rec ntfy !scach */
81 { CURL_MAPI_FN_multi_add_handle, 0, 0, 1, 0 },
82 { CURL_MAPI_FN_multi_assign, 0, 1, 1, 0 },
83 { CURL_MAPI_FN_multi_cleanup, 1, 0, 0, 1 },
84 { CURL_MAPI_FN_multi_fdset, 0, 0, 1, 0 },
85 { CURL_MAPI_FN_multi_get_handles, 0, 1, 1, 0 },
86 { CURL_MAPI_FN_multi_get_offt, 0, 1, 1, 0 },
87 { CURL_MAPI_FN_multi_info_read, 0, 1, 1, 0 },
88 { CURL_MAPI_FN_multi_notify_disable, 0, 1, 1, 0 },
89 { CURL_MAPI_FN_multi_notify_enable, 0, 1, 1, 0 },
90 { CURL_MAPI_FN_multi_perform, 0, 0, 0, 1 },
91 { CURL_MAPI_FN_multi_poll, 0, 0, 1, 0 },
92 { CURL_MAPI_FN_multi_remove_handle, 0, 0, 1, 0 },
93 { CURL_MAPI_FN_multi_setopt, 0, 0, 1, 0 },
94 { CURL_MAPI_FN_multi_socket_action, 0, 0, 0, 1 },
95 { CURL_MAPI_FN_multi_socket_all, 0, 0, 0, 1 },
96 { CURL_MAPI_FN_multi_socket, 0, 0, 0, 1 },
97 { CURL_MAPI_FN_multi_timeout, 0, 0, 1, 1 },
98 { CURL_MAPI_FN_multi_wait, 0, 0, 1, 0 },
99 { CURL_MAPI_FN_multi_waitfds, 0, 0, 1, 0 },
100};
102struct Curl_cbapi_fn_props {
103 Curl_cbapi_fn fn;
104 uint8_t set_readonly; /* only allows readonly, recursive easy calls */
105};
107static const struct Curl_cbapi_fn_props
108cbapi_fn_props[CURL_CBAPI_FN_LAST - CURL_CBAPI_FN_START] = {
109 { CURL_CBAPI_FN_easy_chunk_bgn, 0 },
110 { CURL_CBAPI_FN_easy_chunk_end, 0 },
111 { CURL_CBAPI_FN_easy_closesocket, 0 },
112 { CURL_CBAPI_FN_easy_cr_in_read, 0 },
113 { CURL_CBAPI_FN_easy_cr_in_resume_from, 0 },
114 { CURL_CBAPI_FN_easy_cw_out_cb, 0 },
115 { CURL_CBAPI_FN_easy_fdebug, 1 },
116 { CURL_CBAPI_FN_easy_fnmatch_data, 0 },
117 { CURL_CBAPI_FN_easy_fopensocket, 0 },
118 { CURL_CBAPI_FN_easy_fprereq, 0 },
119 { CURL_CBAPI_FN_easy_fprogress, 0 },
120 { CURL_CBAPI_FN_easy_fread_func, 0 },
121 { CURL_CBAPI_FN_easy_fsockopt, 0 },
122 { CURL_CBAPI_FN_easy_fsslctx, 0 },
123 { CURL_CBAPI_FN_easy_fwrite_rtp, 0 },
124 { CURL_CBAPI_FN_easy_fxferinfo, 0 },
125 { CURL_CBAPI_FN_easy_ioctl_func, 0 },
126 { CURL_CBAPI_FN_easy_resolver_start, 0 },
127 { CURL_CBAPI_FN_easy_seek_func, 0 },
128 { CURL_CBAPI_FN_easy_ssh_hostkeyfunc, 0 },
129 { CURL_CBAPI_FN_easy_ssh_keyfunc, 0 },
130 { CURL_CBAPI_FN_easy_trailer_callback, 0 },
132 { CURL_CBAPI_FN_multi_ntfy_cb, 0 },
133 { CURL_CBAPI_FN_multi_push_cb, 0 },
134 { CURL_CBAPI_FN_multi_socket_cb, 1 },
135 { CURL_CBAPI_FN_multi_timer_cb, 1 },
136};
138static bool eapi_in_readonly_cb(struct Curl_easy *data)
139{
140 struct Curl_multi *multi = data->multi;
141 if(multi && multi->callstack.count) {
142 size_t i;
143 for(i = 0; i < multi->callstack.count; ++i) {
144 if(multi->callstack.calls[i] >= CURL_CBAPI_FN_START) {
145 uint8_t fn = multi->callstack.calls[i];
146 if((fn < CURL_CBAPI_FN_LAST) &&
147 cbapi_fn_props[fn - CURL_CBAPI_FN_START].set_readonly)
148 return TRUE;
149 }
150 }
151 }
152 return FALSE;
153}
155static bool mapi_in_ntfy_cb(struct Curl_multi *multi)
156{
157 if(multi && multi->callstack.count) {
158 size_t i;
159 for(i = 0; i < multi->callstack.count; ++i) {
160 if(multi->callstack.calls[i] == CURL_CBAPI_FN_multi_ntfy_cb)
161 return TRUE;
162 }
163 }
164 return FALSE;
165}
167bool Curl_api_multi_is_in_callback(struct Curl_multi *multi)
168{
169 if(multi && multi->callstack.count) {
170 size_t i;
171 for(i = 0; i < multi->callstack.count; ++i) {
172 if(multi->callstack.calls[i] >= CURL_CBAPI_FN_START)
173 return TRUE;
174 }
175 }
176 return FALSE;
177}
179bool Curl_api_is_in_callback(struct Curl_easy *data)
180{
181 if(data && data->multi) {
182 return Curl_api_multi_is_in_callback(data->multi);
183 }
184 return FALSE;
185}
187bool Curl_eapi_enter(struct Curl_eapi_guard *guard,
188 CURL *curl,
189 Curl_eapi_fn fn,
190 CURLcode *presult)
191{
192 struct Curl_easy *data = curl;
193 const struct Curl_eapi_fn_props *fn_props;
194 CURLcode result = CURLE_OK;
196 guard->depth = 0;
198 /* Verify that we got an easy handle we can work with. */
199 if(!GOOD_EASY_HANDLE(data) || data->state.internal) {
200 result = CURLE_BAD_FUNCTION_ARGUMENT;
201 goto out;
202 }
203 /* verify that is either not added to a multi handle OR has a
204 * GOOD multi handle that knows `data` for `data->mid`. */
205 if(data->mid != UINT32_MAX) {
206 if(GOOD_MULTI_HANDLE(data->multi)) {
207 if(!Curl_multi_knows_easy(data->multi, data)) {
208 /* But multi does not know it, something is fishy, better deny call */
209 DEBUGASSERT(0);
210 result = CURLE_BAD_FUNCTION_ARGUMENT;
211 goto out;
212 }
213 }
214 else {
215 DEBUGASSERT(0); /* data needs to have a GOOD multi handle */
216 result = CURLE_BAD_FUNCTION_ARGUMENT;
217 goto out;
218 }
219 }
220 else if(data->multi) {
221 DEBUGASSERT(0); /* data should not have a multi handle */
222 result = CURLE_BAD_FUNCTION_ARGUMENT;
223 goto out;
224 }
225 /* verify that the call `fn` we're about to enter is known
226 * and check call properties to be admitting. */
227 if(fn >= CURL_EAPI_FN_LAST) {
228 result = CURLE_BAD_FUNCTION_ARGUMENT;
229 goto out;
230 }
231 fn_props = &eapi_fn_props[fn];
232 DEBUGASSERT(fn_props->fn == fn);
233 if(!fn_props->recurse) {
234 if(data->callstack.count) {
235#ifdef CURLVERBOSE
236 DEBUGF(curl_mfprintf(stderr,
237 "EAPI guard: calling %hu with call to %u ongoing\n", (uint16_t)fn,
238 data->callstack.calls[data->callstack.count - 1]));
239#endif
240 result = CURLE_RECURSIVE_API_CALL;
241 goto out;
242 }
243 if(data->multi && data->multi->callstack.count) {
244#ifdef CURLVERBOSE
246 DEBUGF(curl_mfprintf(stderr,
247 "EAPI guard: calling %hu with multi call to %u ongoing\n",
248 (uint16_t)fn,
249 data->multi->callstack.calls[data->multi->callstack.count - 1]));
250#endif
251 result = CURLE_RECURSIVE_API_CALL;
252 goto out;
253 }
254 }
256 if(!fn_props->readonly && eapi_in_readonly_cb(data)) {
257 /* Not allowed to be invoked while an event cb is ongoing */
258#ifdef CURLVERBOSE
259 DEBUGF(curl_mfprintf(stderr,
260 "EAPI guard: calling %hu in readonly enforcing callback\n",
261 (uint16_t)fn));
262#endif
263 result = CURLE_RECURSIVE_API_CALL;
264 goto out;
265 }
267#if defined(USE_SSL) && defined(USE_MUTEX)
268 if(fn_props->no_scache_lock &&
269 Curl_ssl_scache_is_locked_by_current_thread(data)) {
270#ifdef CURLVERBOSE
271 DEBUGF(curl_mfprintf(stderr,
272 "EAPI guard: calling %hu while vtls_scache is locked by "
273 "current thread\n", (uint16_t)fn));
274#endif
275 result = CURLE_RECURSIVE_API_CALL;
276 goto out;
277 }
278#endif
280 /* all fine, add to data's callstack */
281 if(data->callstack.count >= CURL_EAPI_MAX_RECURSION) {
282 result = CURLE_RECURSIVE_API_CALL;
283 goto out;
284 }
285 data->callstack.calls[data->callstack.count] = (uint16_t)fn;
286 ++data->callstack.count;
287 guard->depth = data->callstack.count;
288 guard->data = fn_props->data_is_killed ? NULL : data;
290out:
291 if(presult)
292 *presult = result;
293 return guard->depth > 0;
294}
296void Curl_eapi_leave(struct Curl_eapi_guard *guard)
297{
298 if(guard->depth) {
299 /* guard->data is set when handle is supposed to stay alive during call */
300 if(guard->data && GOOD_EASY_HANDLE(guard->data)) {
301 if(guard->depth > guard->data->callstack.count) {
302 DEBUGASSERT(0); /* something very wrong */
303 }
304 else {
305 if(guard->depth < guard->data->callstack.count) {
306 DEBUGASSERT(0); /* someone forgot to clean up */
307 }
308 /* reset to depth the guard was entered in */
309 guard->data->callstack.count = (uint16_t)(guard->depth - 1);
310 }
311 }
312 }
313}
315CURLHcode Curl_eapi_hcode(CURLcode result)
316{
317 switch(result) {
318 case CURLE_OK:
319 return CURLHE_OK;
320 case CURLE_BAD_FUNCTION_ARGUMENT:
321 return CURLHE_BAD_ARGUMENT;
322 case CURLE_OUT_OF_MEMORY:
323 return CURLHE_OUT_OF_MEMORY;
324 case CURLE_NOT_BUILT_IN:
325 return CURLHE_NOT_BUILT_IN;
326 default:
327 /* Unfortunately, we cannot convert RECURSIVE_API_CALL,
328 * but since the header API is reentrant, this should not happen. */
329 return CURLHE_BAD_ARGUMENT;
330 }
331}
333bool Curl_mapi_enter(struct Curl_mapi_guard *guard,
334 CURLM *m,
335 Curl_mapi_fn fn,
336 CURLMcode *pmresult)
337{
338 struct Curl_multi *multi = m;
339 const struct Curl_mapi_fn_props *fn_props;
340 CURLMcode mresult = CURLM_OK;
342 guard->depth = 0;
344 /* Verify that we got an easy handle we can work with. */
345 if(!GOOD_MULTI_HANDLE(multi)) {
346 mresult = CURLM_BAD_HANDLE;
347 goto out;
348 }
349 if(fn >= CURL_MAPI_FN_LAST) {
350 mresult = CURLM_BAD_FUNCTION_ARGUMENT;
351 goto out;
352 }
353 fn_props = &mapi_fn_props[fn];
354 DEBUGASSERT(fn_props->fn == fn);
355 if(fn_props->allow_ntfy_cb && mapi_in_ntfy_cb(multi)) {
356 /* explicitly allowed, even though normal recursion may not */
357 }
358 else if(!fn_props->recurse && multi->callstack.count) {
359#ifdef CURLVERBOSE
360 DEBUGF(curl_mfprintf(stderr,
361 "MAPI guard: calling %hu with call to %u ongoing\n", (uint16_t)fn,
362 multi->callstack.calls[multi->callstack.count - 1]));
363#endif
364 mresult = CURLM_RECURSIVE_API_CALL;
365 goto out;
366 }
368#if defined(USE_SSL) && defined(USE_MUTEX)
369 if(fn_props->no_scache_lock && multi->ssl_scache &&
370 Curl_ssl_scache_is_locked_by_current_thread(multi->admin)) {
371#ifdef CURLVERBOSE
372 DEBUGF(curl_mfprintf(stderr,
373 "MAPI guard: calling %hu while its vtls_scache is locked by "
374 "current thread\n", (uint16_t)fn));
375#endif
376 mresult = CURLM_RECURSIVE_API_CALL;
377 goto out;
378 }
379#endif
381 /* all fine, add to data's callstack */
382 if(multi->callstack.count >= CURL_MAPI_MAX_RECURSION) {
383 mresult = CURLM_RECURSIVE_API_CALL;
384 goto out;
385 }
386 multi->callstack.calls[multi->callstack.count] = (uint8_t)fn;
387 ++multi->callstack.count;
388 guard->depth = multi->callstack.count;
389 guard->multi = fn_props->multi_is_killed ? NULL : multi;
391out:
392 if(pmresult)
393 *pmresult = mresult;
394 return guard->depth > 0;
395}
397void Curl_mapi_leave(struct Curl_mapi_guard *guard)
398{
399 if(guard->depth) {
400 /* guard->data is set when handle is supposed to stay alive during call */
401 if(guard->multi && GOOD_MULTI_HANDLE(guard->multi)) {
402 if(guard->depth > guard->multi->callstack.count) {
403 DEBUGASSERT(0); /* something very wrong */
404 }
405 else {
406 if(guard->depth < guard->multi->callstack.count) {
407 DEBUGASSERT(0); /* someone forgot to clean up */
408 }
409 /* reset to depth the guard was entered in */
410 guard->multi->callstack.count = (uint8_t)(guard->depth - 1);
411 }
412 }
413 }
414}
416void Curl_cbapi_enter(struct Curl_mapi_guard *guard,
417 struct Curl_easy *data,
418 struct Curl_multi *multi,
419 Curl_cbapi_fn fn)
420{
421 guard->depth = 0;
423 if(!multi)
424 multi = data ? data->multi : NULL;
425 /* if not multi is involved here, just leave */
426 if(!multi)
427 return;
428 /* invalid callback specifier? */
429 if((fn >= CURL_CBAPI_FN_LAST) || (fn < CURL_CBAPI_FN_START)) {
430 DEBUGASSERT(0);
431 return;
432 }
433 DEBUGASSERT(cbapi_fn_props[fn - CURL_CBAPI_FN_START].fn == fn);
434 /* all fine, add to data's callstack */
435 /* if multi callstack already at max depth, leave */
436 if(multi->callstack.count >= CURL_MAPI_MAX_RECURSION) {
437 DEBUGASSERT(0);
438 return;
439 }
440 multi->callstack.calls[multi->callstack.count] = (uint8_t)fn;
441 ++multi->callstack.count;
442 guard->depth = multi->callstack.count;
443 guard->multi = multi;
444}
446void Curl_cbapi_leave(struct Curl_mapi_guard *guard)
447{
448 Curl_mapi_leave(guard);
449}
Diagnostics4 git calls · 50 ms
CallStatusSizeTime050 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 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 · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 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=44 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=86Open pack map
fetch2003.8 KiB · hit44 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=3917 git.response.cache=HIT git.response.duration_ms=44 git.fetch.wants=f313bd4b9f093beb39001b13b4b03297ab43b448 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=3917 git.pkt.payload.max=3896 git.sideband.band1.bytes=3895 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
- a5e217729f6decd4
- Request
- b9c876cb…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format