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 } git_transport_flags_t
;
28 typedef struct git_transport git_transport
;
30 struct git_transport
{
32 /* Set progress and error callbacks */
34 git_transport
*transport
,
35 git_transport_message_cb progress_cb
,
36 git_transport_message_cb error_cb
,
37 git_transport_certificate_check_cb certificate_check_cb
,
40 /* Connect the transport to the remote repository, using the given
43 git_transport
*transport
,
45 git_cred_acquire_cb cred_acquire_cb
,
46 void *cred_acquire_payload
,
50 /* This function may be called after a successful call to
51 * connect(). The array returned is owned by the transport and
52 * is guranteed until the next call of a transport function. */
54 const git_remote_head
***out
,
56 git_transport
*transport
);
58 /* Executes the push whose context is in the git_push object. */
59 int (*push
)(git_transport
*transport
, git_push
*push
);
61 /* This function may be called after a successful call to connect(), when
62 * the direction is FETCH. The function performs a negotiation to calculate
63 * the wants list for the fetch. */
64 int (*negotiate_fetch
)(
65 git_transport
*transport
,
67 const git_remote_head
* const *refs
,
70 /* This function may be called after a successful call to negotiate_fetch(),
71 * when the direction is FETCH. This function retrieves the pack file for
72 * the fetch from the remote end. */
74 git_transport
*transport
,
76 git_transfer_progress
*stats
,
77 git_transfer_progress_cb progress_cb
,
78 void *progress_payload
);
80 /* Checks to see if the transport is connected */
81 int (*is_connected
)(git_transport
*transport
);
83 /* Reads the flags value previously passed into connect() */
84 int (*read_flags
)(git_transport
*transport
, int *flags
);
86 /* Cancels any outstanding transport operation */
87 void (*cancel
)(git_transport
*transport
);
89 /* This function is the reverse of connect() -- it terminates the
90 * connection to the remote end. */
91 int (*close
)(git_transport
*transport
);
93 /* Frees/destructs the git_transport object. */
94 void (*free
)(git_transport
*transport
);
97 #define GIT_TRANSPORT_VERSION 1
98 #define GIT_TRANSPORT_INIT {GIT_TRANSPORT_VERSION}
101 * Initializes a `git_transport` with default values. Equivalent to
102 * creating an instance with GIT_TRANSPORT_INIT.
104 * @param opts the `git_transport` struct to initialize
105 * @param version Version of struct; pass `GIT_TRANSPORT_VERSION`
106 * @return Zero on success; -1 on failure.
108 GIT_EXTERN(int) git_transport_init(
110 unsigned int version
);
113 * Function to use to create a transport from a URL. The transport database
114 * is scanned to find a transport that implements the scheme of the URI (i.e.
115 * git:// or http://) and a transport object is returned to the caller.
117 * @param out The newly created transport (out)
118 * @param owner The git_remote which will own this transport
119 * @param url The URL to connect to
120 * @return 0 or an error code
122 GIT_EXTERN(int) git_transport_new(git_transport
**out
, git_remote
*owner
, const char *url
);
125 * Create an ssh transport with custom git command paths
127 * This is a factory function suitable for setting as the transport
128 * callback in a remote (or for a clone in the options).
130 * The payload argument must be a strarray pointer with the paths for
131 * the `git-upload-pack` and `git-receive-pack` at index 0 and 1.
133 * @param out the resulting transport
134 * @param owner the owning remote
135 * @param payload a strarray with the paths
136 * @return 0 or an error code
138 GIT_EXTERN(int) git_transport_ssh_with_paths(git_transport
**out
, git_remote
*owner
, void *payload
);
140 /* Signature of a function which creates a transport */
141 typedef int (*git_transport_cb
)(git_transport
**out
, git_remote
*owner
, void *param
);
144 * Add a custom transport definition, to be used in addition to the built-in
145 * set of transports that come with libgit2.
147 * The caller is responsible for synchronizing calls to git_transport_register
148 * and git_transport_unregister with other calls to the library that
149 * instantiate transports.
151 * @param prefix The scheme (ending in "://") to match, i.e. "git://"
152 * @param cb The callback used to create an instance of the transport
153 * @param param A fixed parameter to pass to cb at creation time
154 * @return 0 or an error code
156 GIT_EXTERN(int) git_transport_register(
163 * Unregister a custom transport definition which was previously registered
164 * with git_transport_register.
166 * @param prefix From the previous call to git_transport_register
167 * @return 0 or an error code
169 GIT_EXTERN(int) git_transport_unregister(
172 /* Transports which come with libgit2 (match git_transport_cb). The expected
173 * value for "param" is listed in-line below. */
176 * Create an instance of the dummy transport.
178 * @param out The newly created transport (out)
179 * @param owner The git_remote which will own this transport
180 * @param payload You must pass NULL for this parameter.
181 * @return 0 or an error code
183 GIT_EXTERN(int) git_transport_dummy(
186 /* NULL */ void *payload
);
189 * Create an instance of the local transport.
191 * @param out The newly created transport (out)
192 * @param owner The git_remote which will own this transport
193 * @param payload You must pass NULL for this parameter.
194 * @return 0 or an error code
196 GIT_EXTERN(int) git_transport_local(
199 /* NULL */ void *payload
);
202 * Create an instance of the smart transport.
204 * @param out The newly created transport (out)
205 * @param owner The git_remote which will own this transport
206 * @param payload A pointer to a git_smart_subtransport_definition
207 * @return 0 or an error code
209 GIT_EXTERN(int) git_transport_smart(
212 /* (git_smart_subtransport_definition *) */ void *payload
);
215 *** End of base transport interface ***
216 *** Begin interface for subtransports for the smart transport ***
219 /* The smart transport knows how to speak the git protocol, but it has no
220 * knowledge of how to establish a connection between it and another endpoint,
221 * or how to move data back and forth. For this, a subtransport interface is
222 * declared, and the smart transport delegates this work to the subtransports.
223 * Three subtransports are implemented: git, http, and winhttp. (The http and
224 * winhttp transports each implement both http and https.) */
226 /* Subtransports can either be RPC = 0 (persistent connection) or RPC = 1
227 * (request/response). The smart transport handles the differences in its own
228 * logic. The git subtransport is RPC = 0, while http and winhttp are both
231 /* Actions that the smart transport can ask
232 * a subtransport to perform */
234 GIT_SERVICE_UPLOADPACK_LS
= 1,
235 GIT_SERVICE_UPLOADPACK
= 2,
236 GIT_SERVICE_RECEIVEPACK_LS
= 3,
237 GIT_SERVICE_RECEIVEPACK
= 4,
238 } git_smart_service_t
;
240 typedef struct git_smart_subtransport git_smart_subtransport
;
241 typedef struct git_smart_subtransport_stream git_smart_subtransport_stream
;
243 /* A stream used by the smart transport to read and write data
244 * from a subtransport */
245 struct git_smart_subtransport_stream
{
246 /* The owning subtransport */
247 git_smart_subtransport
*subtransport
;
250 git_smart_subtransport_stream
*stream
,
256 git_smart_subtransport_stream
*stream
,
261 git_smart_subtransport_stream
*stream
);
264 /* An implementation of a subtransport which carries data for the
266 struct git_smart_subtransport
{
268 git_smart_subtransport_stream
**out
,
269 git_smart_subtransport
*transport
,
271 git_smart_service_t action
);
273 /* Subtransports are guaranteed a call to close() between
274 * calls to action(), except for the following two "natural" progressions
275 * of actions against a constant URL.
277 * 1. UPLOADPACK_LS -> UPLOADPACK
278 * 2. RECEIVEPACK_LS -> RECEIVEPACK */
279 int (*close
)(git_smart_subtransport
*transport
);
281 void (*free
)(git_smart_subtransport
*transport
);
284 /* A function which creates a new subtransport for the smart transport */
285 typedef int (*git_smart_subtransport_cb
)(
286 git_smart_subtransport
**out
,
287 git_transport
* owner
);
289 typedef struct git_smart_subtransport_definition
{
290 /* The function to use to create the git_smart_subtransport */
291 git_smart_subtransport_cb callback
;
293 /* True if the protocol is stateless; false otherwise. For example,
294 * http:// is stateless, but git:// is not. */
296 } git_smart_subtransport_definition
;
298 /* Smart transport subtransports that come with libgit2 */
301 * Create an instance of the http subtransport. This subtransport
302 * also supports https. On Win32, this subtransport may be implemented
303 * using the WinHTTP library.
305 * @param out The newly created subtransport
306 * @param owner The smart transport to own this subtransport
307 * @return 0 or an error code
309 GIT_EXTERN(int) git_smart_subtransport_http(
310 git_smart_subtransport
**out
,
311 git_transport
* owner
);
314 * Create an instance of the git subtransport.
316 * @param out The newly created subtransport
317 * @param owner The smart transport to own this subtransport
318 * @return 0 or an error code
320 GIT_EXTERN(int) git_smart_subtransport_git(
321 git_smart_subtransport
**out
,
322 git_transport
* owner
);
325 * Create an instance of the ssh subtransport.
327 * @param out The newly created subtransport
328 * @param owner The smart transport to own this subtransport
329 * @return 0 or an error code
331 GIT_EXTERN(int) git_smart_subtransport_ssh(
332 git_smart_subtransport
**out
,
333 git_transport
* owner
);
336 * Sets a custom transport factory for the remote. The caller can use this
337 * function to override the transport used for this remote when performing
338 * network operations.
340 * @param remote the remote to configure
341 * @param transport_cb the function to use to create a transport
342 * @param payload opaque parameter passed to transport_cb
343 * @return 0 or an error code
345 GIT_EXTERN(int) git_remote_set_transport(
347 git_transport_cb transport_cb
,