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 * Flags to pass to transport
30 GIT_TRANSPORTFLAGS_NONE
= 0,
31 } git_transport_flags_t
;
33 typedef struct git_transport git_transport
;
35 struct git_transport
{
37 /* Set progress and error callbacks */
39 git_transport
*transport
,
40 git_transport_message_cb progress_cb
,
41 git_transport_message_cb error_cb
,
42 git_transport_certificate_check_cb certificate_check_cb
,
45 /* Connect the transport to the remote repository, using the given
48 git_transport
*transport
,
50 git_cred_acquire_cb cred_acquire_cb
,
51 void *cred_acquire_payload
,
55 /* This function may be called after a successful call to
56 * connect(). The array returned is owned by the transport and
57 * is guaranteed until the next call of a transport function. */
59 const git_remote_head
***out
,
61 git_transport
*transport
);
63 /* Executes the push whose context is in the git_push object. */
64 int (*push
)(git_transport
*transport
, git_push
*push
);
66 /* This function may be called after a successful call to connect(), when
67 * the direction is FETCH. The function performs a negotiation to calculate
68 * the wants list for the fetch. */
69 int (*negotiate_fetch
)(
70 git_transport
*transport
,
72 const git_remote_head
* const *refs
,
75 /* This function may be called after a successful call to negotiate_fetch(),
76 * when the direction is FETCH. This function retrieves the pack file for
77 * the fetch from the remote end. */
79 git_transport
*transport
,
81 git_transfer_progress
*stats
,
82 git_transfer_progress_cb progress_cb
,
83 void *progress_payload
);
85 /* Checks to see if the transport is connected */
86 int (*is_connected
)(git_transport
*transport
);
88 /* Reads the flags value previously passed into connect() */
89 int (*read_flags
)(git_transport
*transport
, int *flags
);
91 /* Cancels any outstanding transport operation */
92 void (*cancel
)(git_transport
*transport
);
94 /* This function is the reverse of connect() -- it terminates the
95 * connection to the remote end. */
96 int (*close
)(git_transport
*transport
);
98 /* Frees/destructs the git_transport object. */
99 void (*free
)(git_transport
*transport
);
102 #define GIT_TRANSPORT_VERSION 1
103 #define GIT_TRANSPORT_INIT {GIT_TRANSPORT_VERSION}
106 * Initializes a `git_transport` with default values. Equivalent to
107 * creating an instance with GIT_TRANSPORT_INIT.
109 * @param opts the `git_transport` struct to initialize
110 * @param version Version of struct; pass `GIT_TRANSPORT_VERSION`
111 * @return Zero on success; -1 on failure.
113 GIT_EXTERN(int) git_transport_init(
115 unsigned int version
);
118 * Function to use to create a transport from a URL. The transport database
119 * is scanned to find a transport that implements the scheme of the URI (i.e.
120 * git:// or http://) and a transport object is returned to the caller.
122 * @param out The newly created transport (out)
123 * @param owner The git_remote which will own this transport
124 * @param url The URL to connect to
125 * @return 0 or an error code
127 GIT_EXTERN(int) git_transport_new(git_transport
**out
, git_remote
*owner
, const char *url
);
130 * Create an ssh transport with custom git command paths
132 * This is a factory function suitable for setting as the transport
133 * callback in a remote (or for a clone in the options).
135 * The payload argument must be a strarray pointer with the paths for
136 * the `git-upload-pack` and `git-receive-pack` at index 0 and 1.
138 * @param out the resulting transport
139 * @param owner the owning remote
140 * @param payload a strarray with the paths
141 * @return 0 or an error code
143 GIT_EXTERN(int) git_transport_ssh_with_paths(git_transport
**out
, git_remote
*owner
, void *payload
);
145 /* Signature of a function which creates a transport */
146 typedef int (*git_transport_cb
)(git_transport
**out
, git_remote
*owner
, void *param
);
149 * Add a custom transport definition, to be used in addition to the built-in
150 * set of transports that come with libgit2.
152 * The caller is responsible for synchronizing calls to git_transport_register
153 * and git_transport_unregister with other calls to the library that
154 * instantiate transports.
156 * @param prefix The scheme (ending in "://") to match, i.e. "git://"
157 * @param cb The callback used to create an instance of the transport
158 * @param param A fixed parameter to pass to cb at creation time
159 * @return 0 or an error code
161 GIT_EXTERN(int) git_transport_register(
168 * Unregister a custom transport definition which was previously registered
169 * with git_transport_register.
171 * @param prefix From the previous call to git_transport_register
172 * @return 0 or an error code
174 GIT_EXTERN(int) git_transport_unregister(
177 /* Transports which come with libgit2 (match git_transport_cb). The expected
178 * value for "param" is listed in-line below. */
181 * Create an instance of the dummy transport.
183 * @param out The newly created transport (out)
184 * @param owner The git_remote which will own this transport
185 * @param payload You must pass NULL for this parameter.
186 * @return 0 or an error code
188 GIT_EXTERN(int) git_transport_dummy(
191 /* NULL */ void *payload
);
194 * Create an instance of the local transport.
196 * @param out The newly created transport (out)
197 * @param owner The git_remote which will own this transport
198 * @param payload You must pass NULL for this parameter.
199 * @return 0 or an error code
201 GIT_EXTERN(int) git_transport_local(
204 /* NULL */ void *payload
);
207 * Create an instance of the smart transport.
209 * @param out The newly created transport (out)
210 * @param owner The git_remote which will own this transport
211 * @param payload A pointer to a git_smart_subtransport_definition
212 * @return 0 or an error code
214 GIT_EXTERN(int) git_transport_smart(
217 /* (git_smart_subtransport_definition *) */ void *payload
);
220 *** End of base transport interface ***
221 *** Begin interface for subtransports for the smart transport ***
224 /* The smart transport knows how to speak the git protocol, but it has no
225 * knowledge of how to establish a connection between it and another endpoint,
226 * or how to move data back and forth. For this, a subtransport interface is
227 * declared, and the smart transport delegates this work to the subtransports.
228 * Three subtransports are implemented: git, http, and winhttp. (The http and
229 * winhttp transports each implement both http and https.) */
231 /* Subtransports can either be RPC = 0 (persistent connection) or RPC = 1
232 * (request/response). The smart transport handles the differences in its own
233 * logic. The git subtransport is RPC = 0, while http and winhttp are both
236 /* Actions that the smart transport can ask
237 * a subtransport to perform */
239 GIT_SERVICE_UPLOADPACK_LS
= 1,
240 GIT_SERVICE_UPLOADPACK
= 2,
241 GIT_SERVICE_RECEIVEPACK_LS
= 3,
242 GIT_SERVICE_RECEIVEPACK
= 4,
243 } git_smart_service_t
;
245 typedef struct git_smart_subtransport git_smart_subtransport
;
246 typedef struct git_smart_subtransport_stream git_smart_subtransport_stream
;
248 /* A stream used by the smart transport to read and write data
249 * from a subtransport */
250 struct git_smart_subtransport_stream
{
251 /* The owning subtransport */
252 git_smart_subtransport
*subtransport
;
255 git_smart_subtransport_stream
*stream
,
261 git_smart_subtransport_stream
*stream
,
266 git_smart_subtransport_stream
*stream
);
269 /* An implementation of a subtransport which carries data for the
271 struct git_smart_subtransport
{
273 git_smart_subtransport_stream
**out
,
274 git_smart_subtransport
*transport
,
276 git_smart_service_t action
);
278 /* Subtransports are guaranteed a call to close() between
279 * calls to action(), except for the following two "natural" progressions
280 * of actions against a constant URL.
282 * 1. UPLOADPACK_LS -> UPLOADPACK
283 * 2. RECEIVEPACK_LS -> RECEIVEPACK */
284 int (*close
)(git_smart_subtransport
*transport
);
286 void (*free
)(git_smart_subtransport
*transport
);
289 /* A function which creates a new subtransport for the smart transport */
290 typedef int (*git_smart_subtransport_cb
)(
291 git_smart_subtransport
**out
,
292 git_transport
* owner
,
296 * Definition for a "subtransport"
298 * This is used to let the smart protocol code know about the protocol
299 * which you are implementing.
301 typedef struct git_smart_subtransport_definition
{
302 /** The function to use to create the git_smart_subtransport */
303 git_smart_subtransport_cb callback
;
306 * True if the protocol is stateless; false otherwise. For example,
307 * http:// is stateless, but git:// is not.
311 /** Param of the callback
314 } git_smart_subtransport_definition
;
316 /* Smart transport subtransports that come with libgit2 */
319 * Create an instance of the http subtransport. This subtransport
320 * also supports https. On Win32, this subtransport may be implemented
321 * using the WinHTTP library.
323 * @param out The newly created subtransport
324 * @param owner The smart transport to own this subtransport
325 * @return 0 or an error code
327 GIT_EXTERN(int) git_smart_subtransport_http(
328 git_smart_subtransport
**out
,
329 git_transport
* owner
,
333 * Create an instance of the git subtransport.
335 * @param out The newly created subtransport
336 * @param owner The smart transport to own this subtransport
337 * @return 0 or an error code
339 GIT_EXTERN(int) git_smart_subtransport_git(
340 git_smart_subtransport
**out
,
341 git_transport
* owner
,
345 * Create an instance of the ssh subtransport.
347 * @param out The newly created subtransport
348 * @param owner The smart transport to own this subtransport
349 * @return 0 or an error code
351 GIT_EXTERN(int) git_smart_subtransport_ssh(
352 git_smart_subtransport
**out
,
353 git_transport
* owner
,
357 * Sets a custom transport factory for the remote. The caller can use this
358 * function to override the transport used for this remote when performing
359 * network operations.
361 * @param remote the remote to configure
362 * @param transport_cb the function to use to create a transport
363 * @param payload opaque parameter passed to transport_cb
364 * @return 0 or an error code
366 GIT_EXTERN(int) git_remote_set_transport(
368 git_transport_cb transport_cb
,