• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef HEADER_CURL_CONNECT_H
2 #define HEADER_CURL_CONNECT_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
11  *
12  * This software is licensed as described in the file COPYING, which
13  * you should have received as part of this distribution. The terms
14  * are also available at https://curl.se/docs/copyright.html.
15  *
16  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17  * copies of the Software, and permit persons to whom the Software is
18  * furnished to do so, under the terms of the COPYING file.
19  *
20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21  * KIND, either express or implied.
22  *
23  * SPDX-License-Identifier: curl
24  *
25  ***************************************************************************/
26 #include "curl_setup.h"
27 
28 #include "nonblock.h" /* for curlx_nonblock(), formerly Curl_nonblock() */
29 #include "sockaddr.h"
30 #include "timeval.h"
31 
32 struct Curl_dns_entry;
33 
34 /* generic function that returns how much time there's left to run, according
35    to the timeouts set */
36 timediff_t Curl_timeleft(struct Curl_easy *data,
37                          struct curltime *nowp,
38                          bool duringconnect);
39 
40 #define DEFAULT_CONNECT_TIMEOUT 300000 /* milliseconds == five minutes */
41 
42 /*
43  * Used to extract socket and connectdata struct for the most recent
44  * transfer on the given Curl_easy.
45  *
46  * The returned socket will be CURL_SOCKET_BAD in case of failure!
47  */
48 curl_socket_t Curl_getconnectinfo(struct Curl_easy *data,
49                                   struct connectdata **connp);
50 
51 bool Curl_addr2string(struct sockaddr *sa, curl_socklen_t salen,
52                       char *addr, int *port);
53 
54 void Curl_persistconninfo(struct Curl_easy *data, struct connectdata *conn,
55                           char *local_ip, int local_port);
56 
57 /*
58  * Curl_conncontrol() marks the end of a connection/stream. The 'closeit'
59  * argument specifies if it is the end of a connection or a stream.
60  *
61  * For stream-based protocols (such as HTTP/2), a stream close will not cause
62  * a connection close. Other protocols will close the connection for both
63  * cases.
64  *
65  * It sets the bit.close bit to TRUE (with an explanation for debug builds),
66  * when the connection will close.
67  */
68 
69 #define CONNCTRL_KEEP 0 /* undo a marked closure */
70 #define CONNCTRL_CONNECTION 1
71 #define CONNCTRL_STREAM 2
72 
73 void Curl_conncontrol(struct connectdata *conn,
74                       int closeit
75 #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
76                       , const char *reason
77 #endif
78   );
79 
80 #if defined(DEBUGBUILD) && !defined(CURL_DISABLE_VERBOSE_STRINGS)
81 #define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM, y)
82 #define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION, y)
83 #define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP, y)
84 #else /* if !DEBUGBUILD || CURL_DISABLE_VERBOSE_STRINGS */
85 #define streamclose(x,y) Curl_conncontrol(x, CONNCTRL_STREAM)
86 #define connclose(x,y) Curl_conncontrol(x, CONNCTRL_CONNECTION)
87 #define connkeep(x,y) Curl_conncontrol(x, CONNCTRL_KEEP)
88 #endif
89 
90 /**
91  * Create a cfilter for making an "ip" connection to the
92  * given address, using parameters from `conn`. The "ip" connection
93  * can be a TCP socket, a UDP socket or even a QUIC connection.
94  *
95  * It MUST use only the supplied `ai` for its connection attempt.
96  *
97  * Such a filter may be used in "happy eyeball" scenarios, and its
98  * `connect` implementation needs to support non-blocking. Once connected,
99  * it MAY be installed in the connection filter chain to serve transfers.
100  */
101 typedef CURLcode cf_ip_connect_create(struct Curl_cfilter **pcf,
102                                       struct Curl_easy *data,
103                                       struct connectdata *conn,
104                                       const struct Curl_addrinfo *ai,
105                                       int transport);
106 
107 /**
108  * Create a happy eyeball connection filter that uses the, once resolved,
109  * address information to connect on ip families based on connection
110  * configuration.
111  * @param pcf        output, the created cfilter
112  * @param data       easy handle used in creation
113  * @param conn       connection the filter is created for
114  * @param cf_create  method to create the sub-filters performing the
115  *                   actual connects.
116  */
117 CURLcode
118 Curl_cf_happy_eyeballs_create(struct Curl_cfilter **pcf,
119                               struct Curl_easy *data,
120                               struct connectdata *conn,
121                               cf_ip_connect_create *cf_create,
122                               const struct Curl_dns_entry *remotehost,
123                               int transport);
124 
125 CURLcode Curl_cf_setup_add(struct Curl_easy *data,
126                            struct connectdata *conn,
127                            int sockindex,
128                            const struct Curl_dns_entry *remotehost,
129                            int transport,
130                            int ssl_mode);
131 
132 CURLcode Curl_cf_setup_insert_after(struct Curl_cfilter *cf_at,
133                                     struct Curl_easy *data,
134                                     const struct Curl_dns_entry *remotehost,
135                                     int transport,
136                                     int ssl_mode);
137 
138 /**
139  * Setup the cfilters at `sockindex` in connection `conn`.
140  * If no filter chain is installed yet, inspects the configuration
141  * in `data` and `conn? to install a suitable filter chain.
142  */
143 CURLcode Curl_conn_setup(struct Curl_easy *data,
144                          struct connectdata *conn,
145                          int sockindex,
146                          const struct Curl_dns_entry *remotehost,
147                          int ssl_mode);
148 
149 extern struct Curl_cftype Curl_cft_happy_eyeballs;
150 extern struct Curl_cftype Curl_cft_setup;
151 
152 #ifdef DEBUGBUILD
153 void Curl_debug_set_transport_provider(int transport,
154                                        cf_ip_connect_create *cf_create);
155 #endif
156 
157 #endif /* HEADER_CURL_CONNECT_H */
158