2 * Copyright (C) the libgit2 contributors. All rights reserved.
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
8 #ifndef INCLUDE_sys_git_transport_h
9 #define INCLUDE_sys_git_transport_h
12 #include "git2/types.h"
15 * @file git2/sys/transport.h
16 * @brief Git custom transport registration interfaces and functions
17 * @defgroup git_transport Git custom transport registration
25 GIT_TRANSPORTFLAGS_NONE
= 0,
26 /* If the connection is secured with SSL/TLS, the authenticity
27 * of the server certificate should not be verified. */
28 GIT_TRANSPORTFLAGS_NO_CHECK_CERT
= 1
29 } git_transport_flags_t
;
31 typedef struct git_transport git_transport
;
33 struct git_transport
{
35 /* Set progress and error callbacks */
37 git_transport
*transport
,
38 git_transport_message_cb progress_cb
,
39 git_transport_message_cb error_cb
,
40 git_transport_certificate_check_cb certificate_check_cb
,
43 /* Connect the transport to the remote repository, using the given
46 git_transport
*transport
,
48 git_cred_acquire_cb cred_acquire_cb
,
49 void *cred_acquire_payload
,
53 /* This function may be called after a successful call to
54 * connect(). The array returned is owned by the transport and
55 * is guranteed until the next call of a transport function. */
57 const git_remote_head
***out
,
59 git_transport
*transport
);
61 /* Executes the push whose context is in the git_push object. */
62 int (*push
)(git_transport
*transport
, git_push
*push
);
64 /* This function may be called after a successful call to connect(), when
65 * the direction is FETCH. The function performs a negotiation to calculate
66 * the wants list for the fetch. */
67 int (*negotiate_fetch
)(
68 git_transport
*transport
,
70 const git_remote_head
* const *refs
,
73 /* This function may be called after a successful call to negotiate_fetch(),
74 * when the direction is FETCH. This function retrieves the pack file for
75 * the fetch from the remote end. */
77 git_transport
*transport
,
79 git_transfer_progress
*stats
,
80 git_transfer_progress_cb progress_cb
,
81 void *progress_payload
);
83 /* Checks to see if the transport is connected */
84 int (*is_connected
)(git_transport
*transport
);
86 /* Reads the flags value previously passed into connect() */
87 int (*read_flags
)(git_transport
*transport
, int *flags
);
89 /* Cancels any outstanding transport operation */
90 void (*cancel
)(git_transport
*transport
);
92 /* This function is the reverse of connect() -- it terminates the
93 * connection to the remote end. */
94 int (*close
)(git_transport
*transport
);
96 /* Frees/destructs the git_transport object. */
97 void (*free
)(git_transport
*transport
);
100 #define GIT_TRANSPORT_VERSION 1
101 #define GIT_TRANSPORT_INIT {GIT_TRANSPORT_VERSION}
104 * Initializes a `git_transport` with default values. Equivalent to
105 * creating an instance with GIT_TRANSPORT_INIT.
107 * @param opts the `git_transport` struct to initialize
108 * @param version Version of struct; pass `GIT_TRANSPORT_VERSION`
109 * @return Zero on success; -1 on failure.
111 GIT_EXTERN(int) git_transport_init(
113 unsigned int version
);
116 * Function to use to create a transport from a URL. The transport database
117 * is scanned to find a transport that implements the scheme of the URI (i.e.
118 * git:// or http://) and a transport object is returned to the caller.
120 * @param out The newly created transport (out)
121 * @param owner The git_remote which will own this transport
122 * @param url The URL to connect to
123 * @return 0 or an error code
125 GIT_EXTERN(int) git_transport_new(git_transport
**out
, git_remote
*owner
, const char *url
);
128 * Create an ssh transport with custom git command paths
130 * This is a factory function suitable for setting as the transport
131 * callback in a remote (or for a clone in the options).
133 * The payload argument must be a strarray pointer with the paths for
134 * the `git-upload-pack` and `git-receive-pack` at index 0 and 1.
136 * @param out the resulting transport
137 * @param owner the owning remote
138 * @param payload a strarray with the paths
139 * @return 0 or an error code
141 GIT_EXTERN(int) git_transport_ssh_with_paths(git_transport
**out
, git_remote
*owner
, void *payload
);
143 /* Signature of a function which creates a transport */
144 typedef int (*git_transport_cb
)(git_transport
**out
, git_remote
*owner
, void *param
);
147 * Add a custom transport definition, to be used in addition to the built-in
148 * set of transports that come with libgit2.
150 * The caller is responsible for synchronizing calls to git_transport_register
151 * and git_transport_unregister with other calls to the library that
152 * instantiate transports.
154 * @param prefix The scheme (ending in "://") to match, i.e. "git://"
155 * @param cb The callback used to create an instance of the transport
156 * @param param A fixed parameter to pass to cb at creation time
157 * @return 0 or an error code
159 GIT_EXTERN(int) git_transport_register(
166 * Unregister a custom transport definition which was previously registered
167 * with git_transport_register.
169 * @param prefix From the previous call to git_transport_register
170 * @return 0 or an error code
172 GIT_EXTERN(int) git_transport_unregister(
175 /* Transports which come with libgit2 (match git_transport_cb). The expected
176 * value for "param" is listed in-line below. */
179 * Create an instance of the dummy transport.
181 * @param out The newly created transport (out)
182 * @param owner The git_remote which will own this transport
183 * @param payload You must pass NULL for this parameter.
184 * @return 0 or an error code
186 GIT_EXTERN(int) git_transport_dummy(
189 /* NULL */ void *payload
);
192 * Create an instance of the local transport.
194 * @param out The newly created transport (out)
195 * @param owner The git_remote which will own this transport
196 * @param payload You must pass NULL for this parameter.
197 * @return 0 or an error code
199 GIT_EXTERN(int) git_transport_local(
202 /* NULL */ void *payload
);
205 * Create an instance of the smart transport.
207 * @param out The newly created transport (out)
208 * @param owner The git_remote which will own this transport
209 * @param payload A pointer to a git_smart_subtransport_definition
210 * @return 0 or an error code
212 GIT_EXTERN(int) git_transport_smart(
215 /* (git_smart_subtransport_definition *) */ void *payload
);
218 *** End of base transport interface ***
219 *** Begin interface for subtransports for the smart transport ***
222 /* The smart transport knows how to speak the git protocol, but it has no
223 * knowledge of how to establish a connection between it and another endpoint,
224 * or how to move data back and forth. For this, a subtransport interface is
225 * declared, and the smart transport delegates this work to the subtransports.
226 * Three subtransports are implemented: git, http, and winhttp. (The http and
227 * winhttp transports each implement both http and https.) */
229 /* Subtransports can either be RPC = 0 (persistent connection) or RPC = 1
230 * (request/response). The smart transport handles the differences in its own
231 * logic. The git subtransport is RPC = 0, while http and winhttp are both
234 /* Actions that the smart transport can ask
235 * a subtransport to perform */
237 GIT_SERVICE_UPLOADPACK_LS
= 1,
238 GIT_SERVICE_UPLOADPACK
= 2,
239 GIT_SERVICE_RECEIVEPACK_LS
= 3,
240 GIT_SERVICE_RECEIVEPACK
= 4,
241 } git_smart_service_t
;
243 typedef struct git_smart_subtransport git_smart_subtransport
;
244 typedef struct git_smart_subtransport_stream git_smart_subtransport_stream
;
246 /* A stream used by the smart transport to read and write data
247 * from a subtransport */
248 struct git_smart_subtransport_stream
{
249 /* The owning subtransport */
250 git_smart_subtransport
*subtransport
;
253 git_smart_subtransport_stream
*stream
,
259 git_smart_subtransport_stream
*stream
,
264 git_smart_subtransport_stream
*stream
);
267 /* An implementation of a subtransport which carries data for the
269 struct git_smart_subtransport
{
271 git_smart_subtransport_stream
**out
,
272 git_smart_subtransport
*transport
,
274 git_smart_service_t action
);
276 /* Subtransports are guaranteed a call to close() between
277 * calls to action(), except for the following two "natural" progressions
278 * of actions against a constant URL.
280 * 1. UPLOADPACK_LS -> UPLOADPACK
281 * 2. RECEIVEPACK_LS -> RECEIVEPACK */
282 int (*close
)(git_smart_subtransport
*transport
);
284 void (*free
)(git_smart_subtransport
*transport
);
287 /* A function which creates a new subtransport for the smart transport */
288 typedef int (*git_smart_subtransport_cb
)(
289 git_smart_subtransport
**out
,
290 git_transport
* owner
);
292 typedef struct git_smart_subtransport_definition
{
293 /* The function to use to create the git_smart_subtransport */
294 git_smart_subtransport_cb callback
;
296 /* True if the protocol is stateless; false otherwise. For example,
297 * http:// is stateless, but git:// is not. */
299 } git_smart_subtransport_definition
;
301 /* Smart transport subtransports that come with libgit2 */
304 * Create an instance of the http subtransport. This subtransport
305 * also supports https. On Win32, this subtransport may be implemented
306 * using the WinHTTP library.
308 * @param out The newly created subtransport
309 * @param owner The smart transport to own this subtransport
310 * @return 0 or an error code
312 GIT_EXTERN(int) git_smart_subtransport_http(
313 git_smart_subtransport
**out
,
314 git_transport
* owner
);
317 * Create an instance of the git subtransport.
319 * @param out The newly created subtransport
320 * @param owner The smart transport to own this subtransport
321 * @return 0 or an error code
323 GIT_EXTERN(int) git_smart_subtransport_git(
324 git_smart_subtransport
**out
,
325 git_transport
* owner
);
328 * Create an instance of the ssh subtransport.
330 * @param out The newly created subtransport
331 * @param owner The smart transport to own this subtransport
332 * @return 0 or an error code
334 GIT_EXTERN(int) git_smart_subtransport_ssh(
335 git_smart_subtransport
**out
,
336 git_transport
* owner
);
339 * Sets a custom transport factory for the remote. The caller can use this
340 * function to override the transport used for this remote when performing
341 * network operations.
343 * @param remote the remote to configure
344 * @param transport_cb the function to use to create a transport
345 * @param payload opaque parameter passed to transport_cb
346 * @return 0 or an error code
348 GIT_EXTERN(int) git_remote_set_transport(
350 git_transport_cb transport_cb
,