-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompression.diff
More file actions
2089 lines (2026 loc) · 67.5 KB
/
Copy pathcompression.diff
File metadata and controls
2089 lines (2026 loc) · 67.5 KB
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
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--- input/input.c
+++ output/output.c
@@ -178,44 +178,13 @@
Curl_safefree(data->set.str[i]);
}
- for(j = (enum dupblob)0; j < BLOB_LAST; j++) {
- Curl_safefree(data->set.blobs[j]);
- }
-
- if(data->state.referer_alloc) {
- Curl_safefree(data->state.referer);
- data->state.referer_alloc = FALSE;
- }
- data->state.referer = NULL;
- if(data->state.url_alloc) {
- Curl_safefree(data->state.url);
- data->state.url_alloc = FALSE;
- }
- data->state.url = NULL;
-
- Curl_mime_cleanpart(&data->set.mimepost);
-
-#ifndef CURL_DISABLE_COOKIES
- curl_slist_free_all(data->state.cookielist);
- data->state.cookielist = NULL;
+ { … 20 line(s) … ⟦tj:ba01e9e39df077f01a0e37e1d3fb2fc4⟧ }
#endif
-}
/* free the URL pieces */
static void up_free(struct Curl_easy *data)
{
- struct urlpieces *up = &data->state.up;
- Curl_safefree(up->scheme);
- Curl_safefree(up->hostname);
- Curl_safefree(up->port);
- Curl_safefree(up->user);
- Curl_safefree(up->password);
- Curl_safefree(up->options);
- Curl_safefree(up->path);
- Curl_safefree(up->query);
- curl_url_cleanup(data->state.uh);
- data->state.uh = NULL;
-}
+ { … 12 line(s) … ⟦tj:6b3ebdb4fbaf851ef3d32406341df4e4⟧ }
/*
* This is the internal function curl_easy_cleanup() calls. This should
@@ -227,121 +196,9 @@
CURLcode Curl_close(struct Curl_easy **datap)
{
struct Curl_easy *data;
-
- if(!datap || !*datap)
- return CURLE_OK;
-
- data = *datap;
- *datap = NULL;
-
- Curl_expire_clear(data); /* shut off timers */
-
- /* Detach connection if any is left. This should not be normal, but can be
- the case for example with CONNECT_ONLY + recv/send (test 556) */
- Curl_detach_connection(data);
- if(!data->state.internal) {
- if(data->multi)
- /* This handle is still part of a multi handle, take care of this first
- and detach this handle from there. */
- curl_multi_remove_handle(data->multi, data);
-
- if(data->multi_easy) {
- /* when curl_easy_perform() is used, it creates its own multi handle to
- use and this is the one */
- curl_multi_cleanup(data->multi_easy);
- data->multi_easy = NULL;
- }
- }
-
- data->magic = 0; /* force a clear AFTER the possibly enforced removal from
- the multi handle, since that function uses the magic
- field! */
-
- if(data->state.rangestringalloc)
- free(data->state.range);
-
- /* freed here just in case DONE wasn't called */
- Curl_req_free(&data->req, data);
-
- /* Close down all open SSL info and sessions */
- Curl_ssl_close_all(data);
- Curl_safefree(data->state.first_host);
- Curl_safefree(data->state.scratch);
- Curl_ssl_free_certinfo(data);
-
- if(data->state.referer_alloc) {
- Curl_safefree(data->state.referer);
- data->state.referer_alloc = FALSE;
- }
- data->state.referer = NULL;
-
- up_free(data);
- Curl_dyn_free(&data->state.headerb);
- Curl_flush_cookies(data, TRUE);
-#ifndef CURL_DISABLE_ALTSVC
- Curl_altsvc_save(data, data->asi, data->set.str[STRING_ALTSVC]);
- Curl_altsvc_cleanup(&data->asi);
-#endif
-#ifndef CURL_DISABLE_HSTS
- Curl_hsts_save(data, data->hsts, data->set.str[STRING_HSTS]);
- if(!data->share || !data->share->hsts)
- Curl_hsts_cleanup(&data->hsts);
- curl_slist_free_all(data->state.hstslist); /* clean up list */
-#endif
-#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_DIGEST_AUTH)
- Curl_http_auth_cleanup_digest(data);
-#endif
- Curl_safefree(data->info.contenttype);
- Curl_safefree(data->info.wouldredirect);
-
- /* this destroys the channel and we cannot use it anymore after this */
- Curl_resolver_cancel(data);
- Curl_resolver_cleanup(data->state.async.resolver);
- data_priority_cleanup(data);
-
- /* No longer a dirty share, if it exists */
- if(data->share) {
- Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
- data->share->dirty--;
- Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
- }
-
-#ifndef CURL_DISABLE_PROXY
- Curl_safefree(data->state.aptr.proxyuserpwd);
-#endif
- Curl_safefree(data->state.aptr.uagent);
- Curl_safefree(data->state.aptr.userpwd);
- Curl_safefree(data->state.aptr.accept_encoding);
- Curl_safefree(data->state.aptr.te);
- Curl_safefree(data->state.aptr.rangeline);
- Curl_safefree(data->state.aptr.ref);
- Curl_safefree(data->state.aptr.host);
-#ifndef CURL_DISABLE_COOKIES
- Curl_safefree(data->state.aptr.cookiehost);
-#endif
-#ifndef CURL_DISABLE_RTSP
- Curl_safefree(data->state.aptr.rtsp_transport);
-#endif
- Curl_safefree(data->state.aptr.user);
- Curl_safefree(data->state.aptr.passwd);
-#ifndef CURL_DISABLE_PROXY
- Curl_safefree(data->state.aptr.proxyuser);
- Curl_safefree(data->state.aptr.proxypasswd);
-#endif
-
-#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_FORM_API)
- Curl_mime_cleanpart(data->state.formp);
- Curl_safefree(data->state.formp);
-#endif
-
- /* destruct wildcard structures if it is needed */
- Curl_wildcard_dtor(&data->wildcard);
- Curl_freeset(data);
- Curl_headers_cleanup(data);
- free(data);
+ { … 112 line(s) … ⟦tj:51a2f9e711b023f7d7391d632fd33672⟧ }
return CURLE_OK;
-}
/*
* Initialize the UserDefined fields within a Curl_easy.
@@ -351,147 +208,13 @@
{
struct UserDefined *set = &data->set;
CURLcode result = CURLE_OK;
-
- set->out = stdout; /* default output to stdout */
- set->in_set = stdin; /* default input from stdin */
- set->err = stderr; /* default stderr to stderr */
-
- /* use fwrite as default function to store output */
- set->fwrite_func = (curl_write_callback)fwrite;
-
- /* use fread as default function to read input */
- set->fread_func_set = (curl_read_callback)fread;
- set->is_fread_set = 0;
-
- set->seek_client = ZERO_NULL;
-
- set->filesize = -1; /* we don't know the size */
- set->postfieldsize = -1; /* unknown size */
- set->maxredirs = 30; /* sensible default */
-
- set->method = HTTPREQ_GET; /* Default HTTP request */
-#ifndef CURL_DISABLE_RTSP
- set->rtspreq = RTSPREQ_OPTIONS; /* Default RTSP request */
-#endif
-#ifndef CURL_DISABLE_FTP
- set->ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */
- set->ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */
- set->ftp_use_pret = FALSE; /* mainly useful for drftpd servers */
- set->ftp_filemethod = FTPFILE_MULTICWD;
- set->ftp_skip_ip = TRUE; /* skip PASV IP by default */
-#endif
- set->dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
-
- /* Set the default size of the SSL session ID cache */
- set->general_ssl.max_ssl_sessions = 5;
- /* Timeout every 24 hours by default */
- set->general_ssl.ca_cache_timeout = 24 * 60 * 60;
-
- set->httpauth = CURLAUTH_BASIC; /* defaults to basic */
-
-#ifndef CURL_DISABLE_PROXY
- set->proxyport = 0;
- set->proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */
- set->proxyauth = CURLAUTH_BASIC; /* defaults to basic */
- /* SOCKS5 proxy auth defaults to username/password + GSS-API */
- set->socks5auth = CURLAUTH_BASIC | CURLAUTH_GSSAPI;
-#endif
-
- /* make libcurl quiet by default: */
- set->hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */
-
- Curl_mime_initpart(&set->mimepost);
-
- Curl_ssl_easy_config_init(data);
-#ifndef CURL_DISABLE_DOH
- set->doh_verifyhost = TRUE;
- set->doh_verifypeer = TRUE;
-#endif
-#ifdef USE_SSH
- /* defaults to any auth type */
- set->ssh_auth_types = CURLSSH_AUTH_DEFAULT;
- set->new_directory_perms = 0755; /* Default permissions */
-#endif
-
- set->new_file_perms = 0644; /* Default permissions */
- set->allowed_protocols = (curl_prot_t) CURLPROTO_ALL;
- set->redir_protocols = CURLPROTO_HTTP | CURLPROTO_HTTPS | CURLPROTO_FTP |
- CURLPROTO_FTPS;
-
-#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
- /*
- * disallow unprotected protection negotiation NEC reference implementation
- * seem not to follow rfc1961 section 4.3/4.4
- */
- set->socks5_gssapi_nec = FALSE;
-#endif
-
- /* Set the default CA cert bundle/path detected/specified at build time.
- *
- * If Schannel or SecureTransport is the selected SSL backend then these
- * locations are ignored. We allow setting CA location for schannel and
- * securetransport when explicitly specified by the user via
- * CURLOPT_CAINFO / --cacert.
- */
+ { … 82 line(s) … ⟦tj:4daa00cdb2b32322d8f4a25257ce1afe⟧ }
if(Curl_ssl_backend() != CURLSSLBACKEND_SCHANNEL &&
Curl_ssl_backend() != CURLSSLBACKEND_SECURETRANSPORT) {
#if defined(CURL_CA_BUNDLE)
result = Curl_setstropt(&set->str[STRING_SSL_CAFILE], CURL_CA_BUNDLE);
- if(result)
- return result;
-#ifndef CURL_DISABLE_PROXY
- result = Curl_setstropt(&set->str[STRING_SSL_CAFILE_PROXY],
- CURL_CA_BUNDLE);
- if(result)
- return result;
-#endif
-#endif
-#if defined(CURL_CA_PATH)
- result = Curl_setstropt(&set->str[STRING_SSL_CAPATH], CURL_CA_PATH);
- if(result)
- return result;
-#ifndef CURL_DISABLE_PROXY
- result = Curl_setstropt(&set->str[STRING_SSL_CAPATH_PROXY], CURL_CA_PATH);
- if(result)
- return result;
-#endif
-#endif
- }
-
-#ifndef CURL_DISABLE_FTP
- set->wildcard_enabled = FALSE;
- set->chunk_bgn = ZERO_NULL;
- set->chunk_end = ZERO_NULL;
- set->fnmatch = ZERO_NULL;
-#endif
- set->tcp_keepalive = FALSE;
- set->tcp_keepintvl = 60;
- set->tcp_keepidle = 60;
- set->tcp_fastopen = FALSE;
- set->tcp_nodelay = TRUE;
- set->ssl_enable_alpn = TRUE;
- set->expect_100_timeout = 1000L; /* Wait for a second by default. */
- set->sep_headers = TRUE; /* separated header lists by default */
- set->buffer_size = READBUFFER_SIZE;
- set->upload_buffer_size = UPLOADBUFFER_DEFAULT;
- set->happy_eyeballs_timeout = CURL_HET_DEFAULT;
- set->upkeep_interval_ms = CURL_UPKEEP_INTERVAL_DEFAULT;
- set->maxconnects = DEFAULT_CONNCACHE_SIZE; /* for easy handles */
- set->maxage_conn = 118;
- set->maxlifetime_conn = 0;
- set->http09_allowed = FALSE;
-#ifdef USE_HTTP2
- set->httpwant = CURL_HTTP_VERSION_2TLS
-#else
- set->httpwant = CURL_HTTP_VERSION_1_1
-#endif
- ;
-#if defined(USE_HTTP2) || defined(USE_HTTP3)
- memset(&set->priority, 0, sizeof(set->priority));
-#endif
- set->quick_exit = 0L;
+{ … 53 line(s) … ⟦tj:cce30dd0a4149dfc63ad2ce6ae52eac0⟧ }
return result;
-}
/**
* Curl_open()
@@ -514,99 +237,19 @@
return CURLE_OUT_OF_MEMORY;
}
- data->magic = CURLEASY_MAGIC_NUMBER;
-
- Curl_req_init(&data->req);
-
- result = Curl_resolver_init(data, &data->state.async.resolver);
- if(result) {
- DEBUGF(fprintf(stderr, "Error: resolver_init failed\n"));
- Curl_req_free(&data->req, data);
- free(data);
- return result;
- }
-
- result = Curl_init_userdefined(data);
- if(!result) {
- Curl_dyn_init(&data->state.headerb, CURL_MAX_HTTP_HEADER);
- Curl_initinfo(data);
-
- /* most recent connection is not yet defined */
- data->state.lastconnect_id = -1;
- data->state.recent_conn_id = -1;
- /* and not assigned an id yet */
- data->id = -1;
-
- data->progress.flags |= PGRS_HIDE;
- data->state.current_speed = -1; /* init to negative == impossible */
- }
-
- if(result) {
- Curl_resolver_cleanup(data->state.async.resolver);
- Curl_dyn_free(&data->state.headerb);
- Curl_freeset(data);
- Curl_req_free(&data->req, data);
- free(data);
- data = NULL;
- }
- else
- *curl = data;
-
+ { … 38 line(s) … ⟦tj:67f0593bcba62ea9f26507c1645044fb⟧ }
return result;
-}
static void conn_shutdown(struct Curl_easy *data)
{
- DEBUGASSERT(data);
- infof(data, "Closing connection");
+ { … 9 line(s) … ⟦tj:0e61fdefa95a5f80e7f5bd0644cc5873⟧ }
- /* possible left-overs from the async name resolvers */
- Curl_resolver_cancel(data);
-
- Curl_conn_close(data, SECONDARYSOCKET);
- Curl_conn_close(data, FIRSTSOCKET);
-}
-
static void conn_free(struct Curl_easy *data, struct connectdata *conn)
{
size_t i;
- DEBUGASSERT(conn);
-
- for(i = 0; i < ARRAYSIZE(conn->cfilter); ++i) {
- Curl_conn_cf_discard_all(data, conn, (int)i);
- }
-
- Curl_free_idnconverted_hostname(&conn->host);
- Curl_free_idnconverted_hostname(&conn->conn_to_host);
-#ifndef CURL_DISABLE_PROXY
- Curl_free_idnconverted_hostname(&conn->http_proxy.host);
- Curl_free_idnconverted_hostname(&conn->socks_proxy.host);
- Curl_safefree(conn->http_proxy.user);
- Curl_safefree(conn->socks_proxy.user);
- Curl_safefree(conn->http_proxy.passwd);
- Curl_safefree(conn->socks_proxy.passwd);
- Curl_safefree(conn->http_proxy.host.rawalloc); /* http proxy name buffer */
- Curl_safefree(conn->socks_proxy.host.rawalloc); /* socks proxy name buffer */
-#endif
- Curl_safefree(conn->user);
- Curl_safefree(conn->passwd);
- Curl_safefree(conn->sasl_authzid);
- Curl_safefree(conn->options);
- Curl_safefree(conn->oauth_bearer);
- Curl_safefree(conn->host.rawalloc); /* host name buffer */
- Curl_safefree(conn->conn_to_host.rawalloc); /* host name buffer */
- Curl_safefree(conn->hostname_resolve);
- Curl_safefree(conn->secondaryhostname);
- Curl_safefree(conn->localdev);
- Curl_ssl_conn_config_cleanup(conn);
-
-#ifdef USE_UNIX_SOCKETS
- Curl_safefree(conn->unix_domain_socket);
-#endif
-
+ { … 34 line(s) … ⟦tj:42de9f57c0e34054b2f6cc4a61e8ec8f⟧ }
free(conn); /* free all the connection oriented data */
-}
/*
* Disconnects the given connection. Note the connection may not be the
@@ -795,47 +438,8 @@
dead = TRUE;
}
else if(conn->handler->connection_check) {
- /* The protocol has a special method for checking the state of the
- connection. Use it to check if the connection is dead. */
- unsigned int state;
-
- /* briefly attach the connection to this transfer for the purpose of
- checking it */
- Curl_attach_connection(data, conn);
-
- state = conn->handler->connection_check(data, conn, CONNCHECK_ISDEAD);
- dead = (state & CONNRESULT_DEAD);
- /* detach the connection again */
- Curl_detach_connection(data);
-
+ { … 39 line(s) … ⟦tj:a422b13d1ddca95dc222b62afe9f889a⟧ }
}
- else {
- bool input_pending = FALSE;
-
- Curl_attach_connection(data, conn);
- dead = !Curl_conn_is_alive(data, conn, &input_pending);
- if(input_pending) {
- /* For reuse, we want a "clean" connection state. The includes
- * that we expect - in general - no waiting input data. Input
- * waiting might be a TLS Notify Close, for example. We reject
- * that.
- * For protocols where data from other end may arrive at
- * any time (HTTP/2 PING for example), the protocol handler needs
- * to install its own `connection_check` callback.
- */
- dead = TRUE;
- }
- Curl_detach_connection(data);
- }
-
- if(dead) {
- /* remove connection from cache */
- infof(data, "Connection %" CURL_FORMAT_CURL_OFF_T " seems to be dead",
- conn->connection_id);
- Curl_conncache_remove_conn(data, conn, FALSE);
- return TRUE;
- }
- }
return FALSE;
}
@@ -865,16 +469,7 @@
{
struct curltime now = Curl_now();
timediff_t elapsed;
-
- DEBUGASSERT(!data->conn); /* no connection */
- CONNCACHE_LOCK(data);
- elapsed =
- Curl_timediff(now, data->state.conn_cache->last_cleanup);
- CONNCACHE_UNLOCK(data);
-
- if(elapsed >= 1000L) {
- struct connectdata *pruned = NULL;
- while(Curl_conncache_foreach(data, data->state.conn_cache, &pruned,
+ { … 10 line(s) … ⟦tj:8465655cb1dbbe51fcd93a7913f8bcf8⟧ }
call_prune_if_dead)) {
/* unlocked */
@@ -961,322 +556,34 @@
if(IsMultiplexingPossible(data, needle)) {
if(bundle->multiuse == BUNDLE_UNKNOWN) {
if(data->set.pipewait) {
- infof(data, "Server doesn't support multiplex yet, wait");
- *waitpipe = TRUE;
- CONNCACHE_UNLOCK(data);
- return FALSE; /* no reuse */
- }
- infof(data, "Server doesn't support multiplex (yet)");
+ { … 15 line(s) … ⟦tj:74938d4fec9832e4d898a740cbb69d25⟧ }
}
- else if(bundle->multiuse == BUNDLE_MULTIPLEX) {
- if(Curl_multiplex_wanted(data->multi))
- canmultiplex = TRUE;
- else
- infof(data, "Could multiplex, but not asked to");
- }
- else if(bundle->multiuse == BUNDLE_NO_MULTIUSE) {
- infof(data, "Can not multiplex, even if we wanted to");
- }
- }
curr = bundle->conn_list.head;
while(curr) {
struct connectdata *check = curr->ptr;
/* Get next node now. We might remove a dead `check` connection which
- * would invalidate `curr` as well. */
- curr = curr->next;
-
- /* Note that if we use an HTTP proxy in normal mode (no tunneling), we
- * check connections to that proxy and not to the actual remote server.
- */
- if(check->connect_only || check->bits.close)
- /* connect-only or to-be-closed connections will not be reused */
- continue;
-
- if(data->set.ipver != CURL_IPRESOLVE_WHATEVER
- && data->set.ipver != check->ip_version) {
- /* skip because the connection is not via the requested IP version */
- continue;
- }
-
- if(!canmultiplex) {
- if(Curl_resolver_asynch() &&
- /* remote_ip[0] is NUL only if the resolving of the name hasn't
- completed yet and until then we don't reuse this connection */
- !check->primary.remote_ip[0])
- continue;
- }
-
- if(CONN_INUSE(check)) {
- if(!canmultiplex) {
- /* transfer can't be multiplexed and check is in use */
- continue;
- }
- else {
- /* Could multiplex, but not when check belongs to another multi */
- struct Curl_llist_element *e = check->easyq.head;
- struct Curl_easy *entry = e->ptr;
- if(entry->multi != data->multi)
- continue;
- }
- }
-
- if(!Curl_conn_is_connected(check, FIRSTSOCKET)) {
- foundPendingCandidate = TRUE;
- /* Don't pick a connection that hasn't connected yet */
- infof(data, "Connection #%" CURL_FORMAT_CURL_OFF_T
- " isn't open enough, can't reuse", check->connection_id);
- continue;
- }
-
- /* `check` is connected. if it is in use and does not support multiplex,
- * we cannot use it. */
- if(!check->bits.multiplex && CONN_INUSE(check))
- continue;
-
-#ifdef USE_UNIX_SOCKETS
- if(needle->unix_domain_socket) {
- if(!check->unix_domain_socket)
- continue;
- if(strcmp(needle->unix_domain_socket, check->unix_domain_socket))
- continue;
- if(needle->bits.abstract_unix_socket !=
- check->bits.abstract_unix_socket)
- continue;
- }
- else if(check->unix_domain_socket)
- continue;
-#endif
-
- if((needle->handler->flags&PROTOPT_SSL) !=
- (check->handler->flags&PROTOPT_SSL))
- /* don't do mixed SSL and non-SSL connections */
- if(get_protocol_family(check->handler) !=
- needle->handler->protocol || !check->bits.tls_upgraded)
- /* except protocols that have been upgraded via TLS */
- continue;
-
- if(needle->bits.conn_to_host != check->bits.conn_to_host)
- /* don't mix connections that use the "connect to host" feature and
- * connections that don't use this feature */
- continue;
-
- if(needle->bits.conn_to_port != check->bits.conn_to_port)
- /* don't mix connections that use the "connect to port" feature and
- * connections that don't use this feature */
- continue;
-
-#ifndef CURL_DISABLE_PROXY
- if(needle->bits.httpproxy != check->bits.httpproxy ||
- needle->bits.socksproxy != check->bits.socksproxy)
- continue;
-
- if(needle->bits.socksproxy &&
- !socks_proxy_info_matches(&needle->socks_proxy,
- &check->socks_proxy))
- continue;
-
- if(needle->bits.httpproxy) {
- if(needle->bits.tunnel_proxy != check->bits.tunnel_proxy)
- continue;
-
- if(!proxy_info_matches(&needle->http_proxy, &check->http_proxy))
- continue;
-
- if(IS_HTTPS_PROXY(needle->http_proxy.proxytype)) {
- /* https proxies come in different types, http/1.1, h2, ... */
- if(needle->http_proxy.proxytype != check->http_proxy.proxytype)
- continue;
- /* match SSL config to proxy */
- if(!Curl_ssl_conn_config_match(data, check, TRUE)) {
- DEBUGF(infof(data,
- "Connection #%" CURL_FORMAT_CURL_OFF_T
- " has different SSL proxy parameters, can't reuse",
- check->connection_id));
- continue;
- }
- /* the SSL config to the server, which may apply here is checked
- * further below */
- }
- }
-#endif
-
- if(h2upgrade && !check->httpversion && canmultiplex) {
- if(data->set.pipewait) {
- infof(data, "Server upgrade doesn't support multiplex yet, wait");
- *waitpipe = TRUE;
- CONNCACHE_UNLOCK(data);
- return FALSE; /* no reuse */
- }
- infof(data, "Server upgrade cannot be used");
- continue; /* can't be used atm */
- }
-
- if(needle->localdev || needle->localport) {
- /* If we are bound to a specific local end (IP+port), we must not
- reuse a random other one, although if we didn't ask for a
- particular one we can reuse one that was bound.
-
- This comparison is a bit rough and too strict. Since the input
- parameters can be specified in numerous ways and still end up the
- same it would take a lot of processing to make it really accurate.
- Instead, this matching will assume that reuses of bound connections
- will most likely also reuse the exact same binding parameters and
- missing out a few edge cases shouldn't hurt anyone very much.
- */
- if((check->localport != needle->localport) ||
- (check->localportrange != needle->localportrange) ||
- (needle->localdev &&
- (!check->localdev || strcmp(check->localdev, needle->localdev))))
- continue;
- }
-
- if(!(needle->handler->flags & PROTOPT_CREDSPERREQUEST)) {
- /* This protocol requires credentials per connection,
- so verify that we're using the same name and password as well */
- if(Curl_timestrcmp(needle->user, check->user) ||
- Curl_timestrcmp(needle->passwd, check->passwd) ||
+ { … 153 line(s) … ⟦tj:b457faf5cc538af03e8ed6a48cce61a9⟧ }
Curl_timestrcmp(needle->sasl_authzid, check->sasl_authzid) ||
Curl_timestrcmp(needle->oauth_bearer, check->oauth_bearer)) {
/* one of them was different */
continue;
- }
- }
-
- /* GSS delegation differences do not actually affect every connection
- and auth method, but this check takes precaution before efficiency */
- if(needle->gssapi_delegation != check->gssapi_delegation)
- continue;
-
- /* If looking for HTTP and the HTTP version we want is less
- * than the HTTP version of the check connection, continue looking */
- if((needle->handler->protocol & PROTO_FAMILY_HTTP) &&
- (((check->httpversion >= 20) &&
- (data->state.httpwant < CURL_HTTP_VERSION_2_0))
- || ((check->httpversion >= 30) &&
- (data->state.httpwant < CURL_HTTP_VERSION_3))))
- continue;
-#ifdef USE_SSH
- else if(get_protocol_family(needle->handler) & PROTO_FAMILY_SSH) {
- if(!ssh_config_matches(needle, check))
- continue;
- }
-#endif
-#ifndef CURL_DISABLE_FTP
- else if(get_protocol_family(needle->handler) & PROTO_FAMILY_FTP) {
- /* Also match ACCOUNT, ALTERNATIVE-TO-USER, USE_SSL and CCC options */
- if(Curl_timestrcmp(needle->proto.ftpc.account,
- check->proto.ftpc.account) ||
- Curl_timestrcmp(needle->proto.ftpc.alternative_to_user,
- check->proto.ftpc.alternative_to_user) ||
- (needle->proto.ftpc.use_ssl != check->proto.ftpc.use_ssl) ||
- (needle->proto.ftpc.ccc != check->proto.ftpc.ccc))
- continue;
- }
-#endif
-
- /* Additional match requirements if talking TLS OR
- * not talking to a HTTP proxy OR using a tunnel through a proxy */
- if((needle->handler->flags&PROTOPT_SSL)
-#ifndef CURL_DISABLE_PROXY
- || !needle->bits.httpproxy || needle->bits.tunnel_proxy
-#endif
- ) {
- /* Talking the same protocol scheme or a TLS upgraded protocol in the
- * same protocol family? */
- if(!strcasecompare(needle->handler->scheme, check->handler->scheme) &&
- (get_protocol_family(check->handler) !=
- needle->handler->protocol || !check->bits.tls_upgraded))
- continue;
-
- /* If needle has "conn_to_*" set, check must match this */
- if((needle->bits.conn_to_host && !strcasecompare(
- needle->conn_to_host.name, check->conn_to_host.name)) ||
- (needle->bits.conn_to_port &&
- needle->conn_to_port != check->conn_to_port))
- continue;
-
- /* hostname and port must match */
- if(!strcasecompare(needle->host.name, check->host.name) ||
- needle->remote_port != check->remote_port)
- continue;
-
- /* If talking TLS, check needs to use the same SSL options. */
+ { … 62 line(s) … ⟦tj:18b391e5f3bc0f8f3b748fc904a2f539⟧ }
if((needle->handler->flags & PROTOPT_SSL) &&
!Curl_ssl_conn_config_match(data, check, FALSE)) {
DEBUGF(infof(data,
"Connection #%" CURL_FORMAT_CURL_OFF_T
- " has different SSL parameters, can't reuse",
- check->connection_id));
- continue;
- }
- }
-
-#if defined(USE_NTLM)
- /* If we are looking for an HTTP+NTLM connection, check if this is
- already authenticating with the right credentials. If not, keep
- looking so that we can reuse NTLM connections if
- possible. (Especially we must not reuse the same connection if
- partway through a handshake!) */
- if(wantNTLMhttp) {
+ { … 13 line(s) … ⟦tj:8882a4ebb8810db91dd0714bfaf2cccc⟧ }
if(Curl_timestrcmp(needle->user, check->user) ||
Curl_timestrcmp(needle->passwd, check->passwd)) {
/* we prefer a credential match, but this is at least a connection
- that can be reused and "upgraded" to NTLM */
- if(check->http_ntlm_state == NTLMSTATE_NONE)
- chosen = check;
- continue;
- }
- }
- else if(check->http_ntlm_state != NTLMSTATE_NONE) {
- /* Connection is using NTLM auth but we don't want NTLM */
- continue;
- }
-
-#ifndef CURL_DISABLE_PROXY
- /* Same for Proxy NTLM authentication */
- if(wantProxyNTLMhttp) {
- /* Both check->http_proxy.user and check->http_proxy.passwd can be
- * NULL */
- if(!check->http_proxy.user || !check->http_proxy.passwd)
- continue;
-
- if(Curl_timestrcmp(needle->http_proxy.user,
- check->http_proxy.user) ||
- Curl_timestrcmp(needle->http_proxy.passwd,
- check->http_proxy.passwd))
- continue;
- }
- else if(check->proxy_ntlm_state != NTLMSTATE_NONE) {
- /* Proxy connection is using NTLM auth but we don't want NTLM */
- continue;
- }
-#endif
- if(wantNTLMhttp || wantProxyNTLMhttp) {
- /* Credentials are already checked, we may use this connection.
- * With NTLM being weird as it is, we MUST use a
- * connection where it has already been fully negotiated.
- * If it has not, we keep on looking for a better one. */
- chosen = check;
-
- if((wantNTLMhttp &&
- (check->http_ntlm_state != NTLMSTATE_NONE)) ||
+{ … 39 line(s) … ⟦tj:99d43c8a8b0db0fad4fc17f61df092d0⟧ }
(wantProxyNTLMhttp &&
(check->proxy_ntlm_state != NTLMSTATE_NONE))) {
/* We must use this connection, no other */
*force_reuse = TRUE;
- break;
- }
- /* Continue look up for a better connection */
- continue;
- }
-#endif
-
- if(CONN_INUSE(check)) {
- DEBUGASSERT(canmultiplex);
- DEBUGASSERT(check->bits.multiplex);
- /* If multiplexed, make sure we don't go over concurrency limit */
+ { … 11 line(s) … ⟦tj:85ea11b2501f6da4259145abedf63eb1⟧ }
if(CONN_INUSE(check) >=
Curl_multi_max_concurrent_streams(data->multi)) {
infof(data, "client side MAX_CONCURRENT_STREAMS reached"
@@ -1287,20 +594,7 @@
Curl_conn_get_max_concurrent(data, check, FIRSTSOCKET)) {
infof(data, "MAX_CONCURRENT_STREAMS reached, skip (%zu)",
CONN_INUSE(check));
- continue;
- }
- /* When not multiplexed, we have a match here! */
- infof(data, "Multiplexed connection found");
- }
- else if(prune_if_dead(check, data)) {
- /* disconnect it */
- Curl_disconnect(data, check, TRUE);
- continue;
- }
-
- /* We have found a connection. Let's stop searching. */
- chosen = check;
- break;
+ { … 14 line(s) … ⟦tj:eeba483b97b4c11e796e8d1936a98a7c⟧ }
} /* loop over connection bundle */
if(chosen) {
@@ -1665,18 +959,8 @@
(data->set.allowed_protocols & p->protocol)) {
/* it is allowed for "normal" request, now do an extra check if this is
- the result of a redirect */
- if(data->state.this_is_a_follow &&
- !(data->set.redir_protocols & p->protocol))
- /* nope, get out */
- ;
- else {
- /* Perform setup complement if some. */
- conn->handler = conn->given = p;
- /* 'port' and 'remote_port' are set in setup_connection_internals() */
- return CURLE_OK;
+{ … 10 line(s) … ⟦tj:88eba19cf1ebcba6d7c8ff819b2d79d8⟧ }
}
- }
/* The protocol was not found in the table, but we don't have to assign it
to anything since it is already assigned to a dummy-struct in the
@@ -1691,17 +975,7 @@
CURLcode Curl_uc_to_curlcode(CURLUcode uc)
{
- switch(uc) {
- default:
- return CURLE_URL_MALFORMAT;
- case CURLUE_UNSUPPORTED_SCHEME:
- return CURLE_UNSUPPORTED_PROTOCOL;
- case CURLUE_OUT_OF_MEMORY:
- return CURLE_OUT_OF_MEMORY;
- case CURLUE_USER_NOT_ALLOWED:
- return CURLE_LOGIN_DENIED;
- }
-}
+ { … 11 line(s) … ⟦tj:edbb7f665574cf6aaf22261ed7d3a896⟧ }
#ifdef USE_IPV6
/*
@@ -1721,38 +995,8 @@
if(!uc && zoneid) {
char *endp;
unsigned long scope = strtoul(zoneid, &endp, 10);
- if(!*endp && (scope < UINT_MAX))
- /* A plain number, use it directly as a scope id. */
- conn->scope_id = (unsigned int)scope;
-#if defined(HAVE_IF_NAMETOINDEX)
- else {
-#elif defined(_WIN32)
- else if(Curl_if_nametoindex) {
-#endif
-
-#if defined(HAVE_IF_NAMETOINDEX) || defined(_WIN32)
- /* Zone identifier is not numeric */
- unsigned int scopeidx = 0;
-#if defined(_WIN32)
- scopeidx = Curl_if_nametoindex(zoneid);
-#else
- scopeidx = if_nametoindex(zoneid);
-#endif
- if(!scopeidx) {
-#ifndef CURL_DISABLE_VERBOSE_STRINGS
- char buffer[STRERROR_LEN];
- infof(data, "Invalid zoneid: %s; %s", zoneid,
- Curl_strerror(errno, buffer, sizeof(buffer)));
-#endif
- }
- else
- conn->scope_id = scopeidx;
- }
-#endif /* HAVE_IF_NAMETOINDEX || _WIN32 */
-
- free(zoneid);
+ { … 30 line(s) … ⟦tj:a3c54604bd3f1d0a1631a2a488b4500f⟧ }
}
-}
#else
#define zonefrom_url(a,b,c) Curl_nop_stmt
#endif
@@ -1784,38 +1028,13 @@
if(data->set.str[STRING_DEFAULT_PROTOCOL] &&
!Curl_is_absolute_url(data->state.url, NULL, 0, TRUE)) {
- char *url = aprintf("%s://%s", data->set.str[STRING_DEFAULT_PROTOCOL],
- data->state.url);
- if(!url)
- return CURLE_OUT_OF_MEMORY;
- if(data->state.url_alloc)
- free(data->state.url);
- data->state.url = url;
- data->state.url_alloc = TRUE;
- }
+ { … 9 line(s) … ⟦tj:ed27c7559cb96f5c76f44e56fddf9ce5⟧ }
if(!use_set_uh) {
char *newurl;
uc = curl_url_set(uh, CURLUPART_URL, data->state.url,
- CURLU_GUESS_SCHEME |
- CURLU_NON_SUPPORT_SCHEME |
- (data->set.disallow_username_in_url ?
- CURLU_DISALLOW_USER : 0) |
- (data->set.path_as_is ? CURLU_PATH_AS_IS : 0));
- if(uc) {
- failf(data, "URL rejected: %s", curl_url_strerror(uc));
- return Curl_uc_to_curlcode(uc);
- }
-
- /* after it was parsed, get the generated normalized version */
- uc = curl_url_get(uh, CURLUPART_URL, &newurl, 0);
- if(uc)
- return Curl_uc_to_curlcode(uc);
- if(data->state.url_alloc)
- free(data->state.url);
- data->state.url = newurl;
+ { … 17 line(s) … ⟦tj:5abf356a098a24165a85cc14f85c8f55⟧ }
data->state.url_alloc = TRUE;
- }
uc = curl_url_get(uh, CURLUPART_SCHEME, &data->state.up.scheme, 0);
if(uc)
@@ -1833,18 +1052,8 @@
hostname = data->state.up.hostname;
if(hostname && hostname[0] == '[') {
- /* This looks like an IPv6 address literal. See if there is an address
- scope. */
- size_t hlen;
- conn->bits.ipv6_ip = TRUE;
- /* cut off the brackets! */
- hostname++;
- hlen = strlen(hostname);
- hostname[hlen - 1] = 0;
+ { … 11 line(s) … ⟦tj:bc0a41bc306a81df09d06e576a237f6d⟧ }
- zonefrom_url(uh, data, conn);
- }
-
/* make sure the connect struct gets its own copy of the host name */
conn->host.rawalloc = strdup(hostname ? hostname : "");
if(!conn->host.rawalloc)
@@ -1863,28 +1072,8 @@
if(data->hsts && strcasecompare("http", data->state.up.scheme)) {
/* This MUST use the IDN decoded name */
if(Curl_hsts(data->hsts, conn->host.name, TRUE)) {
- char *url;
- Curl_safefree(data->state.up.scheme);
- uc = curl_url_set(uh, CURLUPART_SCHEME, "https", 0);
- if(uc)
- return Curl_uc_to_curlcode(uc);
- if(data->state.url_alloc)
- Curl_safefree(data->state.url);
- /* after update, get the updated version */
- uc = curl_url_get(uh, CURLUPART_URL, &url, 0);
- if(uc)
- return Curl_uc_to_curlcode(uc);
- uc = curl_url_get(uh, CURLUPART_SCHEME, &data->state.up.scheme, 0);
- if(uc) {