1 /* 2 * Copyright (C) the libgit2 contributors. All rights reserved. 3 * 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. 6 */ 7 module libgit2_d.sys.transport; 8 9 10 private static import libgit2_d.cert; 11 private static import libgit2_d.credential; 12 private static import libgit2_d.indexer; 13 private static import libgit2_d.proxy; 14 private static import libgit2_d.strarray; 15 private static import libgit2_d.sys.credential; 16 private static import libgit2_d.transport; 17 private static import libgit2_d.types; 18 19 /** 20 * @file git2/sys/transport.h 21 * @brief Git custom transport registration interfaces and functions 22 * @defgroup git_transport Git custom transport registration 23 * @ingroup Git 24 * @{ 25 */ 26 27 extern (C): 28 nothrow @nogc: 29 package(libgit2_d): 30 31 /** 32 * Flags to pass to transport 33 * 34 * Currently unused. 35 */ 36 enum git_transport_flags_t 37 { 38 GIT_TRANSPORTFLAGS_NONE = 0, 39 } 40 41 //Declaration name in C language 42 enum 43 { 44 GIT_TRANSPORTFLAGS_NONE = .git_transport_flags_t.GIT_TRANSPORTFLAGS_NONE, 45 } 46 47 struct git_transport 48 { 49 /** 50 * The struct version 51 */ 52 uint version_; 53 54 /** 55 * Set progress and error callbacks 56 */ 57 int function(.git_transport* transport, libgit2_d.transport.git_transport_message_cb progress_cb, libgit2_d.transport.git_transport_message_cb error_cb, libgit2_d.cert.git_transport_certificate_check_cb certificate_check_cb, void* payload) set_callbacks; 58 59 /** 60 * Set custom headers for HTTP requests 61 */ 62 int function(.git_transport* transport, const (libgit2_d.strarray.git_strarray)* custom_headers) set_custom_headers; 63 64 /** 65 * Connect the transport to the remote repository, using the given 66 * direction. 67 */ 68 int function(.git_transport* transport, const (char)* url, libgit2_d.credential.git_credential_acquire_cb cred_acquire_cb, void* cred_acquire_payload, const (libgit2_d.proxy.git_proxy_options)* proxy_opts, int direction, int flags) connect; 69 70 /** 71 * Get the list of available references in the remote repository. 72 * 73 * This function may be called after a successful call to 74 * `connect()`. The array returned is owned by the transport and 75 * must be kept valid until the next call to one of its functions. 76 */ 77 int function(const (libgit2_d.types.git_remote_head)*** out_, size_t* size, .git_transport* transport) ls; 78 79 /** 80 * Executes the push whose context is in the git_push object. 81 */ 82 int function(.git_transport* transport, libgit2_d.types.git_push* push, const (libgit2_d.types.git_remote_callbacks)* callbacks) push; 83 84 /** 85 * Negotiate a fetch with the remote repository. 86 * 87 * This function may be called after a successful call to `connect()`, 88 * when the direction is git_direction.GIT_DIRECTION_FETCH. The function performs a 89 * negotiation to calculate the `wants` list for the fetch. 90 */ 91 int function(.git_transport* transport, libgit2_d.types.git_repository* repo, const (libgit2_d.types.git_remote_head)* /+ const +/ * refs, size_t count) negotiate_fetch; 92 93 /** 94 * Start downloading the packfile from the remote repository. 95 * 96 * This function may be called after a successful call to 97 * negotiate_fetch(), when the direction is git_direction.GIT_DIRECTION_FETCH. 98 */ 99 int function(.git_transport* transport, libgit2_d.types.git_repository* repo, libgit2_d.indexer.git_indexer_progress* stats, libgit2_d.indexer.git_indexer_progress_cb progress_cb, void* progress_payload) download_pack; 100 101 /** 102 * Checks to see if the transport is connected 103 */ 104 int function(.git_transport* transport) is_connected; 105 106 /** 107 * Reads the flags value previously passed into connect() 108 */ 109 int function(.git_transport* transport, int* flags) read_flags; 110 111 /** 112 * Cancels any outstanding transport operation 113 */ 114 void function(.git_transport* transport) cancel; 115 116 /** 117 * Close the connection to the remote repository. 118 * 119 * This function is the reverse of connect() -- it terminates the 120 * connection to the remote end. 121 */ 122 int function(.git_transport* transport) close; 123 124 /** 125 * Frees/destructs the git_transport object. 126 */ 127 void function(.git_transport* transport) free; 128 } 129 130 enum GIT_TRANSPORT_VERSION = 1; 131 132 pragma(inline, true) 133 pure nothrow @safe @nogc 134 .git_transport GIT_TRANSPORT_INIT() 135 136 do 137 { 138 .git_transport OUTPUT = 139 { 140 version_: .GIT_TRANSPORT_VERSION, 141 }; 142 143 return OUTPUT; 144 } 145 146 /** 147 * Initializes a `git_transport` with default values. Equivalent to 148 * creating an instance with GIT_TRANSPORT_INIT. 149 * 150 * Params: 151 * opts = the `git_transport` struct to initialize 152 * version = Version of struct; pass `GIT_TRANSPORT_VERSION` 153 * 154 * Returns: Zero on success; -1 on failure. 155 */ 156 //GIT_EXTERN 157 int git_transport_init(.git_transport* opts, uint version_); 158 159 /** 160 * Function to use to create a transport from a URL. The transport database 161 * is scanned to find a transport that implements the scheme of the URI (i.e. 162 * git:// or http://) and a transport object is returned to the caller. 163 * 164 * Params: 165 * out_ = The newly created transport (out) 166 * owner = The git_remote which will own this transport 167 * url = The URL to connect to 168 * 169 * Returns: 0 or an error code 170 */ 171 //GIT_EXTERN 172 int git_transport_new(.git_transport** out_, libgit2_d.types.git_remote* owner, const (char)* url); 173 174 /** 175 * Create an ssh transport with custom git command paths 176 * 177 * This is a factory function suitable for setting as the transport 178 * callback in a remote (or for a clone in the options). 179 * 180 * The payload argument must be a strarray pointer with the paths for 181 * the `git-upload-pack` and `git-receive-pack` at index 0 and 1. 182 * 183 * Params: 184 * out_ = the resulting transport 185 * owner = the owning remote 186 * payload = a strarray with the paths 187 * 188 * Returns: 0 or an error code 189 */ 190 //GIT_EXTERN 191 int git_transport_ssh_with_paths(.git_transport** out_, libgit2_d.types.git_remote* owner, void* payload); 192 193 /** 194 * Add a custom transport definition, to be used in addition to the built-in 195 * set of transports that come with libgit2. 196 * 197 * The caller is responsible for synchronizing calls to git_transport_register 198 * and git_transport_unregister with other calls to the library that 199 * instantiate transports. 200 * 201 * Params: 202 * prefix = The scheme (ending in "://") to match, i.e. "git://" 203 * cb = The callback used to create an instance of the transport 204 * param = A fixed parameter to pass to cb at creation time 205 * 206 * Returns: 0 or an error code 207 */ 208 //GIT_EXTERN 209 int git_transport_register(const (char)* prefix, libgit2_d.transport.git_transport_cb cb, void* param); 210 211 /** 212 * Unregister a custom transport definition which was previously registered 213 * with git_transport_register. 214 * 215 * The caller is responsible for synchronizing calls to git_transport_register 216 * and git_transport_unregister with other calls to the library that 217 * instantiate transports. 218 * 219 * Params: 220 * prefix = From the previous call to git_transport_register 221 * 222 * Returns: 0 or an error code 223 */ 224 //GIT_EXTERN 225 int git_transport_unregister(const (char)* prefix); 226 227 /* 228 * Transports which come with libgit2 (match git_transport_cb). The expected 229 * value for "param" is listed in-line below. 230 */ 231 232 /** 233 * Create an instance of the dummy transport. 234 * 235 * Params: 236 * out_ = The newly created transport (out) 237 * owner = The git_remote which will own this transport 238 * payload = You must pass null for this parameter. 239 * 240 * Returns: 0 or an error code 241 */ 242 //GIT_EXTERN 243 int git_transport_dummy(.git_transport** out_, libgit2_d.types.git_remote* owner, /* null */ void* payload); 244 245 /** 246 * Create an instance of the local transport. 247 * 248 * Params: 249 * out_ = The newly created transport (out) 250 * owner = The git_remote which will own this transport 251 * payload = You must pass null for this parameter. 252 * 253 * Returns: 0 or an error code 254 */ 255 //GIT_EXTERN 256 int git_transport_local(.git_transport** out_, libgit2_d.types.git_remote* owner, /* null */ void* payload); 257 258 /** 259 * Create an instance of the smart transport. 260 * 261 * Params: 262 * out_ = The newly created transport (out) 263 * owner = The git_remote which will own this transport 264 * payload = A pointer to a git_smart_subtransport_definition 265 * 266 * Returns: 0 or an error code 267 */ 268 //GIT_EXTERN 269 int git_transport_smart(.git_transport** out_, libgit2_d.types.git_remote* owner, /* (git_smart_subtransport_definition *) */ void* payload); 270 271 /** 272 * Call the certificate check for this transport. 273 * 274 * Params: 275 * transport = a smart transport 276 * cert = the certificate to pass to the caller 277 * valid = whether we believe the certificate is valid 278 * hostname = the hostname we connected to 279 * 280 * Returns: the return value of the callback: 0 for no error, git_error_code.GIT_PASSTHROUGH to indicate that there is no callback registered (or the callback refused to validate the certificate and callers should behave as if no callback was set), or < 0 for an error 281 */ 282 //GIT_EXTERN 283 int git_transport_smart_certificate_check(.git_transport* transport, libgit2_d.types.git_cert* cert, int valid, const (char)* hostname); 284 285 /** 286 * Call the credentials callback for this transport 287 * 288 * Params: 289 * out_ = the pointer where the creds are to be stored 290 * transport = a smart transport 291 * user = the user we saw on the url (if any) 292 * methods = available methods for authentication 293 * 294 * Returns: the return value of the callback: 0 for no error, git_error_code.GIT_PASSTHROUGH to indicate that there is no callback registered (or the callback refused to provide credentials and callers should behave as if no callback was set), or < 0 for an error 295 */ 296 //GIT_EXTERN 297 int git_transport_smart_credentials(libgit2_d.sys.credential.git_credential** out_, .git_transport* transport, const (char)* user, int methods); 298 299 /** 300 * Get a copy of the proxy options 301 * 302 * The url is copied and must be freed by the caller. 303 * 304 * Params: 305 * out_ = options struct to fill 306 * transport = the transport to extract the data from. 307 */ 308 //GIT_EXTERN 309 int git_transport_smart_proxy_options(libgit2_d.proxy.git_proxy_options* out_, .git_transport* transport); 310 311 /* 312 *** End of base transport interface *** 313 *** Begin interface for subtransports for the smart transport *** 314 */ 315 316 /** 317 * Actions that the smart transport can ask a subtransport to perform 318 */ 319 enum git_smart_service_t 320 { 321 GIT_SERVICE_UPLOADPACK_LS = 1, 322 GIT_SERVICE_UPLOADPACK = 2, 323 GIT_SERVICE_RECEIVEPACK_LS = 3, 324 GIT_SERVICE_RECEIVEPACK = 4, 325 } 326 327 //Declaration name in C language 328 enum 329 { 330 GIT_SERVICE_UPLOADPACK_LS = .git_smart_service_t.GIT_SERVICE_UPLOADPACK_LS, 331 GIT_SERVICE_UPLOADPACK = .git_smart_service_t.GIT_SERVICE_UPLOADPACK, 332 GIT_SERVICE_RECEIVEPACK_LS = .git_smart_service_t.GIT_SERVICE_RECEIVEPACK_LS, 333 GIT_SERVICE_RECEIVEPACK = .git_smart_service_t.GIT_SERVICE_RECEIVEPACK, 334 } 335 336 /** 337 * A stream used by the smart transport to read and write data 338 * from a subtransport. 339 * 340 * This provides a customization point in case you need to 341 * support some other communication method. 342 */ 343 struct git_smart_subtransport_stream 344 { 345 /** 346 * The owning subtransport 347 */ 348 .git_smart_subtransport* subtransport; 349 350 /** 351 * Read available data from the stream. 352 * 353 * The implementation may read less than requested. 354 */ 355 int function(.git_smart_subtransport_stream* stream, char* buffer, size_t buf_size, size_t* bytes_read) read; 356 357 /** 358 * Write data to the stream 359 * 360 * The implementation must write all data or return an error. 361 */ 362 int function(.git_smart_subtransport_stream* stream, const (char)* buffer, size_t len) write; 363 364 /** 365 * Free the stream 366 */ 367 void function(.git_smart_subtransport_stream* stream) free; 368 } 369 370 /** 371 * An implementation of a subtransport which carries data for the 372 * smart transport 373 */ 374 struct git_smart_subtransport 375 { 376 /** 377 * Setup a subtransport stream for the requested action. 378 */ 379 int function(.git_smart_subtransport_stream** out_, .git_smart_subtransport* transport, const (char)* url, .git_smart_service_t action) action; 380 381 /** 382 * Close the subtransport. 383 * 384 * Subtransports are guaranteed a call to close() between 385 * calls to action(), except for the following two "natural" progressions 386 * of actions against a constant URL: 387 * 388 * - UPLOADPACK_LS -> UPLOADPACK 389 * - RECEIVEPACK_LS -> RECEIVEPACK 390 */ 391 int function(.git_smart_subtransport* transport) close; 392 393 /** 394 * Free the subtransport 395 */ 396 void function(.git_smart_subtransport* transport) free; 397 } 398 399 /** 400 * A function which creates a new subtransport for the smart transport 401 */ 402 alias git_smart_subtransport_cb = int function(.git_smart_subtransport** out_, .git_transport* owner, void* param); 403 404 /** 405 * Definition for a "subtransport" 406 * 407 * The smart transport knows how to speak the git protocol, but it has no 408 * knowledge of how to establish a connection between it and another endpoint, 409 * or how to move data back and forth. For this, a subtransport interface is 410 * declared, and the smart transport delegates this work to the subtransports. 411 * 412 * Three subtransports are provided by libgit2: ssh, git, http(s). 413 * 414 * Subtransports can either be RPC = 0 (persistent connection) or RPC = 1 415 * (request/response). The smart transport handles the differences in its own 416 * logic. The git subtransport is RPC = 0, while http is RPC = 1. 417 */ 418 struct git_smart_subtransport_definition 419 { 420 /** 421 * The function to use to create the git_smart_subtransport 422 */ 423 .git_smart_subtransport_cb callback; 424 425 /** 426 * True if the protocol is stateless; false otherwise. For example, 427 * http:// is stateless, but git:// is not. 428 */ 429 uint rpc; 430 431 /** 432 * User-specified parameter passed to the callback 433 */ 434 void* param; 435 } 436 437 /* Smart transport subtransports that come with libgit2 */ 438 439 /** 440 * Create an instance of the http subtransport. 441 * 442 * This subtransport also supports https. 443 * 444 * Params: 445 * out_ = The newly created subtransport 446 * owner = The smart transport to own this subtransport 447 * 448 * Returns: 0 or an error code 449 */ 450 //GIT_EXTERN 451 int git_smart_subtransport_http(.git_smart_subtransport** out_, .git_transport* owner, void* param); 452 453 /** 454 * Create an instance of the git subtransport. 455 * 456 * Params: 457 * out_ = The newly created subtransport 458 * owner = The smart transport to own this subtransport 459 * 460 * Returns: 0 or an error code 461 */ 462 //GIT_EXTERN 463 int git_smart_subtransport_git(.git_smart_subtransport** out_, .git_transport* owner, void* param); 464 465 /** 466 * Create an instance of the ssh subtransport. 467 * 468 * Params: 469 * out_ = The newly created subtransport 470 * owner = The smart transport to own this subtransport 471 * 472 * Returns: 0 or an error code 473 */ 474 //GIT_EXTERN 475 int git_smart_subtransport_ssh(.git_smart_subtransport** out_, .git_transport* owner, void* param); 476 477 /** @} */