|
||||
File indexing completed on 2025-01-18 09:59:36
0001 /* 0002 * Copyright (C) the libgit2 contributors. All rights reserved. 0003 * 0004 * This file is part of libgit2, distributed under the GNU GPL v2 with 0005 * a Linking Exception. For full terms see the included COPYING file. 0006 */ 0007 0008 #ifndef INCLUDE_sys_git_transport_h 0009 #define INCLUDE_sys_git_transport_h 0010 0011 #include "git2/net.h" 0012 #include "git2/oidarray.h" 0013 #include "git2/proxy.h" 0014 #include "git2/remote.h" 0015 #include "git2/strarray.h" 0016 #include "git2/transport.h" 0017 #include "git2/types.h" 0018 0019 /** 0020 * @file git2/sys/transport.h 0021 * @brief Git custom transport registration interfaces and functions 0022 * @defgroup git_transport Git custom transport registration 0023 * @ingroup Git 0024 * @{ 0025 */ 0026 0027 GIT_BEGIN_DECL 0028 0029 typedef struct { 0030 const git_remote_head * const *refs; 0031 size_t refs_len; 0032 git_oid *shallow_roots; 0033 size_t shallow_roots_len; 0034 int depth; 0035 } git_fetch_negotiation; 0036 0037 struct git_transport { 0038 unsigned int version; /**< The struct version */ 0039 0040 /** 0041 * Connect the transport to the remote repository, using the given 0042 * direction. 0043 */ 0044 int GIT_CALLBACK(connect)( 0045 git_transport *transport, 0046 const char *url, 0047 int direction, 0048 const git_remote_connect_options *connect_opts); 0049 0050 /** 0051 * Resets the connect options for the given transport. This 0052 * is useful for updating settings or callbacks for an already 0053 * connected transport. 0054 */ 0055 int GIT_CALLBACK(set_connect_opts)( 0056 git_transport *transport, 0057 const git_remote_connect_options *connect_opts); 0058 0059 /** 0060 * Gets the capabilities for this remote repository. 0061 * 0062 * This function may be called after a successful call to 0063 * `connect()`. 0064 */ 0065 int GIT_CALLBACK(capabilities)( 0066 unsigned int *capabilities, 0067 git_transport *transport); 0068 0069 #ifdef GIT_EXPERIMENTAL_SHA256 0070 /** 0071 * Gets the object type for the remote repository. 0072 * 0073 * This function may be called after a successful call to 0074 * `connect()`. 0075 */ 0076 int GIT_CALLBACK(oid_type)( 0077 git_oid_t *object_type, 0078 git_transport *transport); 0079 #endif 0080 0081 /** 0082 * Get the list of available references in the remote repository. 0083 * 0084 * This function may be called after a successful call to 0085 * `connect()`. The array returned is owned by the transport and 0086 * must be kept valid until the next call to one of its functions. 0087 */ 0088 int GIT_CALLBACK(ls)( 0089 const git_remote_head ***out, 0090 size_t *size, 0091 git_transport *transport); 0092 0093 /** Executes the push whose context is in the git_push object. */ 0094 int GIT_CALLBACK(push)( 0095 git_transport *transport, 0096 git_push *push); 0097 0098 /** 0099 * Negotiate a fetch with the remote repository. 0100 * 0101 * This function may be called after a successful call to `connect()`, 0102 * when the direction is GIT_DIRECTION_FETCH. The function performs a 0103 * negotiation to calculate the `wants` list for the fetch. 0104 */ 0105 int GIT_CALLBACK(negotiate_fetch)( 0106 git_transport *transport, 0107 git_repository *repo, 0108 const git_fetch_negotiation *fetch_data); 0109 0110 /** 0111 * Return the shallow roots of the remote. 0112 * 0113 * This function may be called after a successful call to 0114 * `negotiate_fetch`. 0115 */ 0116 int GIT_CALLBACK(shallow_roots)( 0117 git_oidarray *out, 0118 git_transport *transport); 0119 0120 /** 0121 * Start downloading the packfile from the remote repository. 0122 * 0123 * This function may be called after a successful call to 0124 * negotiate_fetch(), when the direction is GIT_DIRECTION_FETCH. 0125 */ 0126 int GIT_CALLBACK(download_pack)( 0127 git_transport *transport, 0128 git_repository *repo, 0129 git_indexer_progress *stats); 0130 0131 /** Checks to see if the transport is connected */ 0132 int GIT_CALLBACK(is_connected)(git_transport *transport); 0133 0134 /** Cancels any outstanding transport operation */ 0135 void GIT_CALLBACK(cancel)(git_transport *transport); 0136 0137 /** 0138 * Close the connection to the remote repository. 0139 * 0140 * This function is the reverse of connect() -- it terminates the 0141 * connection to the remote end. 0142 */ 0143 int GIT_CALLBACK(close)(git_transport *transport); 0144 0145 /** Frees/destructs the git_transport object. */ 0146 void GIT_CALLBACK(free)(git_transport *transport); 0147 }; 0148 0149 #define GIT_TRANSPORT_VERSION 1 0150 #define GIT_TRANSPORT_INIT {GIT_TRANSPORT_VERSION} 0151 0152 /** 0153 * Initializes a `git_transport` with default values. Equivalent to 0154 * creating an instance with GIT_TRANSPORT_INIT. 0155 * 0156 * @param opts the `git_transport` struct to initialize 0157 * @param version Version of struct; pass `GIT_TRANSPORT_VERSION` 0158 * @return Zero on success; -1 on failure. 0159 */ 0160 GIT_EXTERN(int) git_transport_init( 0161 git_transport *opts, 0162 unsigned int version); 0163 0164 /** 0165 * Function to use to create a transport from a URL. The transport database 0166 * is scanned to find a transport that implements the scheme of the URI (i.e. 0167 * git:// or http://) and a transport object is returned to the caller. 0168 * 0169 * @param out The newly created transport (out) 0170 * @param owner The git_remote which will own this transport 0171 * @param url The URL to connect to 0172 * @return 0 or an error code 0173 */ 0174 GIT_EXTERN(int) git_transport_new(git_transport **out, git_remote *owner, const char *url); 0175 0176 /** 0177 * Create an ssh transport with custom git command paths 0178 * 0179 * This is a factory function suitable for setting as the transport 0180 * callback in a remote (or for a clone in the options). 0181 * 0182 * The payload argument must be a strarray pointer with the paths for 0183 * the `git-upload-pack` and `git-receive-pack` at index 0 and 1. 0184 * 0185 * @param out the resulting transport 0186 * @param owner the owning remote 0187 * @param payload a strarray with the paths 0188 * @return 0 or an error code 0189 */ 0190 GIT_EXTERN(int) git_transport_ssh_with_paths(git_transport **out, git_remote *owner, void *payload); 0191 0192 /** 0193 * Add a custom transport definition, to be used in addition to the built-in 0194 * set of transports that come with libgit2. 0195 * 0196 * The caller is responsible for synchronizing calls to git_transport_register 0197 * and git_transport_unregister with other calls to the library that 0198 * instantiate transports. 0199 * 0200 * @param prefix The scheme (ending in "://") to match, i.e. "git://" 0201 * @param cb The callback used to create an instance of the transport 0202 * @param param A fixed parameter to pass to cb at creation time 0203 * @return 0 or an error code 0204 */ 0205 GIT_EXTERN(int) git_transport_register( 0206 const char *prefix, 0207 git_transport_cb cb, 0208 void *param); 0209 0210 /** 0211 * Unregister a custom transport definition which was previously registered 0212 * with git_transport_register. 0213 * 0214 * The caller is responsible for synchronizing calls to git_transport_register 0215 * and git_transport_unregister with other calls to the library that 0216 * instantiate transports. 0217 * 0218 * @param prefix From the previous call to git_transport_register 0219 * @return 0 or an error code 0220 */ 0221 GIT_EXTERN(int) git_transport_unregister( 0222 const char *prefix); 0223 0224 /* Transports which come with libgit2 (match git_transport_cb). The expected 0225 * value for "param" is listed in-line below. */ 0226 0227 /** 0228 * Create an instance of the dummy transport. 0229 * 0230 * @param out The newly created transport (out) 0231 * @param owner The git_remote which will own this transport 0232 * @param payload You must pass NULL for this parameter. 0233 * @return 0 or an error code 0234 */ 0235 GIT_EXTERN(int) git_transport_dummy( 0236 git_transport **out, 0237 git_remote *owner, 0238 /* NULL */ void *payload); 0239 0240 /** 0241 * Create an instance of the local transport. 0242 * 0243 * @param out The newly created transport (out) 0244 * @param owner The git_remote which will own this transport 0245 * @param payload You must pass NULL for this parameter. 0246 * @return 0 or an error code 0247 */ 0248 GIT_EXTERN(int) git_transport_local( 0249 git_transport **out, 0250 git_remote *owner, 0251 /* NULL */ void *payload); 0252 0253 /** 0254 * Create an instance of the smart transport. 0255 * 0256 * @param out The newly created transport (out) 0257 * @param owner The git_remote which will own this transport 0258 * @param payload A pointer to a git_smart_subtransport_definition 0259 * @return 0 or an error code 0260 */ 0261 GIT_EXTERN(int) git_transport_smart( 0262 git_transport **out, 0263 git_remote *owner, 0264 /* (git_smart_subtransport_definition *) */ void *payload); 0265 0266 /** 0267 * Call the certificate check for this transport. 0268 * 0269 * @param transport a smart transport 0270 * @param cert the certificate to pass to the caller 0271 * @param valid whether we believe the certificate is valid 0272 * @param hostname the hostname we connected to 0273 * @return the return value of the callback: 0 for no error, GIT_PASSTHROUGH 0274 * to indicate that there is no callback registered (or the callback 0275 * refused to validate the certificate and callers should behave as 0276 * if no callback was set), or < 0 for an error 0277 */ 0278 GIT_EXTERN(int) git_transport_smart_certificate_check(git_transport *transport, git_cert *cert, int valid, const char *hostname); 0279 0280 /** 0281 * Call the credentials callback for this transport 0282 * 0283 * @param out the pointer where the creds are to be stored 0284 * @param transport a smart transport 0285 * @param user the user we saw on the url (if any) 0286 * @param methods available methods for authentication 0287 * @return the return value of the callback: 0 for no error, GIT_PASSTHROUGH 0288 * to indicate that there is no callback registered (or the callback 0289 * refused to provide credentials and callers should behave as if no 0290 * callback was set), or < 0 for an error 0291 */ 0292 GIT_EXTERN(int) git_transport_smart_credentials(git_credential **out, git_transport *transport, const char *user, int methods); 0293 0294 /** 0295 * Get a copy of the remote connect options 0296 * 0297 * All data is copied and must be freed by the caller by calling 0298 * `git_remote_connect_options_dispose`. 0299 * 0300 * @param out options struct to fill 0301 * @param transport the transport to extract the data from. 0302 */ 0303 GIT_EXTERN(int) git_transport_remote_connect_options( 0304 git_remote_connect_options *out, 0305 git_transport *transport); 0306 0307 /* 0308 *** End of base transport interface *** 0309 *** Begin interface for subtransports for the smart transport *** 0310 */ 0311 0312 /** Actions that the smart transport can ask a subtransport to perform */ 0313 typedef enum { 0314 GIT_SERVICE_UPLOADPACK_LS = 1, 0315 GIT_SERVICE_UPLOADPACK = 2, 0316 GIT_SERVICE_RECEIVEPACK_LS = 3, 0317 GIT_SERVICE_RECEIVEPACK = 4 0318 } git_smart_service_t; 0319 0320 typedef struct git_smart_subtransport git_smart_subtransport; 0321 typedef struct git_smart_subtransport_stream git_smart_subtransport_stream; 0322 0323 /** 0324 * A stream used by the smart transport to read and write data 0325 * from a subtransport. 0326 * 0327 * This provides a customization point in case you need to 0328 * support some other communication method. 0329 */ 0330 struct git_smart_subtransport_stream { 0331 git_smart_subtransport *subtransport; /**< The owning subtransport */ 0332 0333 /** 0334 * Read available data from the stream. 0335 * 0336 * The implementation may read less than requested. 0337 */ 0338 int GIT_CALLBACK(read)( 0339 git_smart_subtransport_stream *stream, 0340 char *buffer, 0341 size_t buf_size, 0342 size_t *bytes_read); 0343 0344 /** 0345 * Write data to the stream 0346 * 0347 * The implementation must write all data or return an error. 0348 */ 0349 int GIT_CALLBACK(write)( 0350 git_smart_subtransport_stream *stream, 0351 const char *buffer, 0352 size_t len); 0353 0354 /** Free the stream */ 0355 void GIT_CALLBACK(free)( 0356 git_smart_subtransport_stream *stream); 0357 }; 0358 0359 /** 0360 * An implementation of a subtransport which carries data for the 0361 * smart transport 0362 */ 0363 struct git_smart_subtransport { 0364 /** 0365 * Setup a subtransport stream for the requested action. 0366 */ 0367 int GIT_CALLBACK(action)( 0368 git_smart_subtransport_stream **out, 0369 git_smart_subtransport *transport, 0370 const char *url, 0371 git_smart_service_t action); 0372 0373 /** 0374 * Close the subtransport. 0375 * 0376 * Subtransports are guaranteed a call to close() between 0377 * calls to action(), except for the following two "natural" progressions 0378 * of actions against a constant URL: 0379 * 0380 * - UPLOADPACK_LS -> UPLOADPACK 0381 * - RECEIVEPACK_LS -> RECEIVEPACK 0382 */ 0383 int GIT_CALLBACK(close)(git_smart_subtransport *transport); 0384 0385 /** Free the subtransport */ 0386 void GIT_CALLBACK(free)(git_smart_subtransport *transport); 0387 }; 0388 0389 /** A function which creates a new subtransport for the smart transport */ 0390 typedef int GIT_CALLBACK(git_smart_subtransport_cb)( 0391 git_smart_subtransport **out, 0392 git_transport *owner, 0393 void *param); 0394 0395 /** 0396 * Definition for a "subtransport" 0397 * 0398 * The smart transport knows how to speak the git protocol, but it has no 0399 * knowledge of how to establish a connection between it and another endpoint, 0400 * or how to move data back and forth. For this, a subtransport interface is 0401 * declared, and the smart transport delegates this work to the subtransports. 0402 * 0403 * Three subtransports are provided by libgit2: ssh, git, http(s). 0404 * 0405 * Subtransports can either be RPC = 0 (persistent connection) or RPC = 1 0406 * (request/response). The smart transport handles the differences in its own 0407 * logic. The git subtransport is RPC = 0, while http is RPC = 1. 0408 */ 0409 typedef struct git_smart_subtransport_definition { 0410 /** The function to use to create the git_smart_subtransport */ 0411 git_smart_subtransport_cb callback; 0412 0413 /** 0414 * True if the protocol is stateless; false otherwise. For example, 0415 * http:// is stateless, but git:// is not. 0416 */ 0417 unsigned rpc; 0418 0419 /** User-specified parameter passed to the callback */ 0420 void *param; 0421 } git_smart_subtransport_definition; 0422 0423 /* Smart transport subtransports that come with libgit2 */ 0424 0425 /** 0426 * Create an instance of the http subtransport. 0427 * 0428 * This subtransport also supports https. 0429 * 0430 * @param out The newly created subtransport 0431 * @param owner The smart transport to own this subtransport 0432 * @return 0 or an error code 0433 */ 0434 GIT_EXTERN(int) git_smart_subtransport_http( 0435 git_smart_subtransport **out, 0436 git_transport *owner, 0437 void *param); 0438 0439 /** 0440 * Create an instance of the git subtransport. 0441 * 0442 * @param out The newly created subtransport 0443 * @param owner The smart transport to own this subtransport 0444 * @return 0 or an error code 0445 */ 0446 GIT_EXTERN(int) git_smart_subtransport_git( 0447 git_smart_subtransport **out, 0448 git_transport *owner, 0449 void *param); 0450 0451 /** 0452 * Create an instance of the ssh subtransport. 0453 * 0454 * @param out The newly created subtransport 0455 * @param owner The smart transport to own this subtransport 0456 * @return 0 or an error code 0457 */ 0458 GIT_EXTERN(int) git_smart_subtransport_ssh( 0459 git_smart_subtransport **out, 0460 git_transport *owner, 0461 void *param); 0462 0463 /** @} */ 0464 GIT_END_DECL 0465 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |