]>
Commit | Line | Data |
---|---|---|
bb742ede | 1 | /* |
5e0de328 | 2 | * Copyright (C) 2009-2012 the libgit2 contributors |
bb742ede VM |
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 | */ | |
8f866dae CMN |
7 | #ifndef INCLUDE_transport_h__ |
8 | #define INCLUDE_transport_h__ | |
9 | ||
8f866dae | 10 | #include "git2/net.h" |
dee5515a | 11 | #include "git2/indexer.h" |
8f866dae | 12 | #include "vector.h" |
66024c7c CMN |
13 | #include "posix.h" |
14 | #include "common.h" | |
64d01de8 | 15 | #include "netops.h" |
d3e1367f CMN |
16 | #ifdef GIT_SSL |
17 | # include <openssl/ssl.h> | |
18 | # include <openssl/err.h> | |
19 | #endif | |
20 | ||
8f866dae | 21 | |
0437d991 | 22 | #define GIT_CAP_OFS_DELTA "ofs-delta" |
114dc6e1 | 23 | #define GIT_CAP_MULTI_ACK "multi_ack" |
e03e71da CMN |
24 | #define GIT_CAP_SIDE_BAND "side-band" |
25 | #define GIT_CAP_SIDE_BAND_64K "side-band-64k" | |
24f2f94e | 26 | #define GIT_CAP_INCLUDE_TAG "include-tag" |
0437d991 CMN |
27 | |
28 | typedef struct git_transport_caps { | |
29 | int common:1, | |
114dc6e1 | 30 | ofs_delta:1, |
e03e71da CMN |
31 | multi_ack: 1, |
32 | side_band:1, | |
24f2f94e CMN |
33 | side_band_64k:1, |
34 | include_tag:1; | |
0437d991 CMN |
35 | } git_transport_caps; |
36 | ||
d3e1367f CMN |
37 | #ifdef GIT_SSL |
38 | typedef struct gitno_ssl { | |
39 | SSL_CTX *ctx; | |
40 | SSL *ssl; | |
41 | } gitno_ssl; | |
42 | #endif | |
43 | ||
44 | ||
8f866dae CMN |
45 | /* |
46 | * A day in the life of a network operation | |
47 | * ======================================== | |
48 | * | |
49 | * The library gets told to ls-remote/push/fetch on/to/from some | |
50 | * remote. We look at the URL of the remote and fill the function | |
51 | * table with whatever is appropriate (the remote may be git over git, | |
52 | * ssh or http(s). It may even be an hg or svn repository, the library | |
53 | * at this level doesn't care, it just calls the helpers. | |
54 | * | |
55 | * The first call is to ->connect() which connects to the remote, | |
56 | * making use of the direction if necessary. This function must also | |
57 | * store the remote heads and any other information it needs. | |
58 | * | |
79e9c3ec CMN |
59 | * The next useful step is to call ->ls() to get the list of |
60 | * references available to the remote. These references may have been | |
61 | * collected on connect, or we may build them now. For ls-remote, | |
62 | * nothing else is needed other than closing the connection. | |
63 | * Otherwise, the higher leves decide which objects we want to | |
64 | * have. ->send_have() is used to tell the other end what we have. If | |
65 | * we do need to download a pack, ->download_pack() is called. | |
66 | * | |
67 | * When we're done, we call ->close() to close the | |
68 | * connection. ->free() takes care of freeing all the resources. | |
8f866dae CMN |
69 | */ |
70 | ||
71 | struct git_transport { | |
72 | /** | |
73 | * Where the repo lives | |
74 | */ | |
75 | char *url; | |
8f866dae CMN |
76 | /** |
77 | * Whether we want to push or fetch | |
78 | */ | |
a7e34e3c | 79 | int direction : 1, /* 0 fetch, 1 push */ |
66024c7c | 80 | connected : 1, |
250b95b2 | 81 | check_cert: 1, |
0048372a | 82 | use_ssl : 1, |
b49c8f71 CMN |
83 | own_logic: 1, /* transitional */ |
84 | rpc: 1; /* git-speak for the HTTP transport */ | |
a6f24a5b | 85 | #ifdef GIT_SSL |
66024c7c CMN |
86 | struct gitno_ssl ssl; |
87 | #endif | |
ad4b5beb | 88 | git_vector refs; |
114dc6e1 | 89 | git_vector common; |
64d01de8 | 90 | gitno_buffer buffer; |
66024c7c | 91 | GIT_SOCKET socket; |
64d01de8 | 92 | git_transport_caps caps; |
e03e71da | 93 | void *cb_data; |
8f866dae CMN |
94 | /** |
95 | * Connect and store the remote heads | |
96 | */ | |
0ac2726f | 97 | int (*connect)(struct git_transport *transport, int dir); |
64d01de8 CMN |
98 | /** |
99 | * Send our side of a negotiation | |
100 | */ | |
101 | int (*negotiation_step)(struct git_transport *transport, void *data, size_t len); | |
8f866dae CMN |
102 | /** |
103 | * Push the changes over | |
104 | */ | |
105 | int (*push)(struct git_transport *transport); | |
22f65b9e CMN |
106 | /** |
107 | * Negotiate the minimal amount of objects that need to be | |
108 | * retrieved | |
109 | */ | |
d88d4311 | 110 | int (*negotiate_fetch)(struct git_transport *transport, git_repository *repo, const git_vector *wants); |
da290220 CMN |
111 | /** |
112 | * Download the packfile | |
113 | */ | |
7a520f5d | 114 | int (*download_pack)(struct git_transport *transport, git_repository *repo, git_off_t *bytes, git_indexer_stats *stats); |
8f866dae CMN |
115 | /** |
116 | * Close the connection | |
117 | */ | |
118 | int (*close)(struct git_transport *transport); | |
d6258deb CMN |
119 | /** |
120 | * Free the associated resources | |
121 | */ | |
122 | void (*free)(struct git_transport *transport); | |
e03e71da CMN |
123 | /** |
124 | * Callbacks for the progress and error output | |
125 | */ | |
126 | void (*progress_cb)(const char *str, int len, void *data); | |
127 | void (*error_cb)(const char *str, int len, void *data); | |
8f866dae CMN |
128 | }; |
129 | ||
d88d4311 VM |
130 | |
131 | int git_transport_new(struct git_transport **transport, const char *url); | |
4e913309 CMN |
132 | int git_transport_local(struct git_transport **transport); |
133 | int git_transport_git(struct git_transport **transport); | |
3d975abc | 134 | int git_transport_http(struct git_transport **transport); |
66024c7c | 135 | int git_transport_https(struct git_transport **transport); |
4e913309 | 136 | int git_transport_dummy(struct git_transport **transport); |
7a544966 RW |
137 | |
138 | /** | |
139 | Returns true if the passed URL is valid (a URL with a Git supported scheme, | |
140 | or pointing to an existing path) | |
141 | */ | |
d88d4311 VM |
142 | int git_transport_valid_url(const char *url); |
143 | ||
d88d4311 | 144 | typedef int (*git_transport_cb)(git_transport **transport); |
8f866dae CMN |
145 | |
146 | #endif |