1 /*
2  *             Copyright Andrej Mitrovic 2013.
3  *  Distributed under the Boost Software License, Version 1.0.
4  *     (See accompanying file LICENSE_1_0.txt or copy at
5  *           http://www.boost.org/LICENSE_1_0.txt)
6  */
7 module git.transport;
8 
9 import std.conv;
10 import std.exception;
11 import std.stdio;
12 import std..string;
13 import std.typecons;
14 
15 import deimos.git2.clone;
16 
17 import git.credentials;
18 import git.checkout;
19 import git.exception;
20 import git.repository;
21 import git.types;
22 import git.util;
23 
24 import deimos.git2.indexer;
25 import deimos.git2.net;
26 import deimos.git2.transport;
27 import deimos.git2.types;
28 import deimos.git2.util;
29 
30 version (GIT_SSH)
31 {
32     static assert(0, "dlibgit does not support SSH yet.");
33 }
34 
35 ///
36 enum GitTransportFlags
37 {
38     ///
39     none = GIT_TRANSPORTFLAGS_NONE,
40 
41     /* *
42         If the connection is secured with SSL/TLS, the authenticity
43         of the server certificate should not be verified.
44     */
45 	no_check_cert = GIT_TRANSPORTFLAGS_NO_CHECK_CERT
46 }
47 
48 ///
49 //~ alias GitTransportMsgCallback = void function(in char[] str);
50 
51 //~ struct GitTransport
52 //~ {
53 	/* Set progress and error callbacks */
54 	//~ int function(GitTransport transport,
55 		//~ GitTransportMsgCallback progressCallback,
56 		//~ GitTransportMsgCallback errorCallbak) setCallbacks;
57 
58 	/* Connect the transport to the remote repository, using the given
59 	 * direction. */
60 	//~ int function(GitTransport transport,
61 		//~ in char[] url,
62 		//~ GitCredAcquireCallback credAcquireCallback,
63 		//~ int direction,
64 		//~ int flags) connect;
65 
66 	//~ /* This function may be called after a successful call to connect(). The
67 	 //~ * provided callback is invoked for each ref discovered on the remote
68 	 //~ * end. */
69 	//~ int function(git_transport *transport,
70 		//~ git_headlist_cb list_cb,
71 		//~ void *payload) ls;
72 
73 	//~ /* Executes the push whose context is in the git_push object. */
74 	//~ int function(git_transport *transport, git_push *push) push;
75 
76 	//~ /* This function may be called after a successful call to connect(), when
77 	 //~ * the direction is FETCH. The function performs a negotiation to calculate
78 	 //~ * the wants list for the fetch. */
79 	//~ int function(git_transport *transport,
80 		//~ git_repository *repo,
81 		//~ const(git_remote_head**) refs_,
82 		//~ size_t count) negotiate_fetch;
83 
84 	//~ /* This function may be called after a successful call to negotiate_fetch(),
85 	 //~ * when the direction is FETCH. This function retrieves the pack file for
86 	 //~ * the fetch from the remote end. */
87 	//~ int function(git_transport *transport,
88 		//~ git_repository *repo,
89 		//~ git_transfer_progress *stats,
90 		//~ git_transfer_progress_callback progress_cb,
91 		//~ void *progress_payload) download_pack;
92 
93 	//~ /* Checks to see if the transport is connected */
94 	//~ int function(git_transport *transport) is_connected;
95 
96 	//~ /* Reads the flags value previously passed into connect() */
97 	//~ int function(git_transport *transport, int *flags) read_flags;
98 
99 	//~ /* Cancels any outstanding transport operation */
100 	//~ void function(git_transport *transport) cancel;
101 
102 	//~ /* This function is the reverse of connect() -- it terminates the
103 	 //~ * connection to the remote end. */
104 	//~ int function(git_transport *transport) close;
105 
106 	//~ /* Frees/destructs the git_transport object. */
107 	//~ void function(git_transport *transport) free;
108 //~ }
109 
110 //~ enum GIT_TRANSPORT_VERSION = 1;
111 //~ enum git_transport GIT_TRANSPORT_INIT = { GIT_TRANSPORT_VERSION };
112 
113 //~ /**
114  //~ * Function to use to create a transport from a URL. The transport database
115  //~ * is scanned to find a transport that implements the scheme of the URI (i.e.
116  //~ * git:// or http://) and a transport object is returned to the caller.
117  //~ *
118  //~ * @param out The newly created transport (out)
119  //~ * @param owner The git_remote which will own this transport
120  //~ * @param url The URL to connect to
121  //~ * @return 0 or an error code
122  //~ */
123 //~ int git_transport_new(git_transport **out_, git_remote *owner, const(char)* url);
124 
125 //~ /* Signature of a function which creates a transport */
126 //~ alias git_transport_cb = int function(git_transport **out_, git_remote *owner, void *param);
127 
128 //~ /* Transports which come with libgit2 (match git_transport_cb). The expected
129  //~ * value for "param" is listed in-line below. */
130 
131 //~ /**
132  //~ * Create an instance of the dummy transport.
133  //~ *
134  //~ * @param out The newly created transport (out)
135  //~ * @param owner The git_remote which will own this transport
136  //~ * @param payload You must pass NULL for this parameter.
137  //~ * @return 0 or an error code
138  //~ */
139 //~ int git_transport_dummy(
140 	//~ git_transport **out_,
141 	//~ git_remote *owner,
142 	//~ /* NULL */ void *payload);
143 
144 //~ /**
145  //~ * Create an instance of the local transport.
146  //~ *
147  //~ * @param out The newly created transport (out)
148  //~ * @param owner The git_remote which will own this transport
149  //~ * @param payload You must pass NULL for this parameter.
150  //~ * @return 0 or an error code
151  //~ */
152 //~ int git_transport_local(
153 	//~ git_transport **out_,
154 	//~ git_remote *owner,
155 	//~ /* NULL */ void *payload);
156 
157 //~ /**
158  //~ * Create an instance of the smart transport.
159  //~ *
160  //~ * @param out The newly created transport (out)
161  //~ * @param owner The git_remote which will own this transport
162  //~ * @param payload A pointer to a git_smart_subtransport_definition
163  //~ * @return 0 or an error code
164  //~ */
165 //~ int git_transport_smart(
166 	//~ git_transport **out_,
167 	//~ git_remote *owner,
168 	//~ /* (git_smart_subtransport_definition *) */ void *payload);
169 
170 //~ /*
171  //~ *** End of base transport interface ***
172  //~ *** Begin interface for subtransports for the smart transport ***
173  //~ */
174 
175 //~ /* The smart transport knows how to speak the git protocol, but it has no
176  //~ * knowledge of how to establish a connection between it and another endpoint,
177  //~ * or how to move data back and forth. For this, a subtransport interface is
178  //~ * declared, and the smart transport delegates this work to the subtransports.
179  //~ * Three subtransports are implemented: git, http, and winhttp. (The http and
180  //~ * winhttp transports each implement both http and https.) */
181 
182 //~ /* Subtransports can either be RPC = 0 (persistent connection) or RPC = 1
183  //~ * (request/response). The smart transport handles the differences in its own
184  //~ * logic. The git subtransport is RPC = 0, while http and winhttp are both
185  //~ * RPC = 1. */
186 
187 //~ /* Actions that the smart transport can ask
188  //~ * a subtransport to perform */
189 //~ enum git_smart_service_t {
190 	//~ GIT_SERVICE_UPLOADPACK_LS = 1,
191 	//~ GIT_SERVICE_UPLOADPACK = 2,
192 	//~ GIT_SERVICE_RECEIVEPACK_LS = 3,
193 	//~ GIT_SERVICE_RECEIVEPACK = 4,
194 //~ } ;
195 
196 //~ mixin _ExportEnumMembers!git_smart_service_t;
197 
198 //~ /* A stream used by the smart transport to read and write data
199  //~ * from a subtransport */
200 //~ struct git_smart_subtransport_stream {
201 	//~ /* The owning subtransport */
202 	//~ git_smart_subtransport *subtransport;
203 
204 	//~ int function(
205 			//~ git_smart_subtransport_stream *stream,
206 			//~ char *buffer,
207 			//~ size_t buf_size,
208 			//~ size_t *bytes_read) read;
209 
210 	//~ int function(
211 			//~ git_smart_subtransport_stream *stream,
212 			//~ const(char)* buffer,
213 			//~ size_t len) write;
214 
215 	//~ void function(
216 			//~ git_smart_subtransport_stream *stream) free;
217 //~ } ;
218 
219 //~ /* An implementation of a subtransport which carries data for the
220  //~ * smart transport */
221 //~ struct git_smart_subtransport {
222 	//~ int function(
223 			//~ git_smart_subtransport_stream **out_,
224 			//~ git_smart_subtransport *transport,
225 			//~ const(char)* url,
226 			//~ git_smart_service_t action) action;
227 
228 	//~ /* Subtransports are guaranteed a call to close() between
229 	 //~ * calls to action(), except for the following two "natural" progressions
230 	 //~ * of actions against a constant URL.
231 	 //~ *
232 	 //~ * 1. UPLOADPACK_LS -> UPLOADPACK
233 	 //~ * 2. RECEIVEPACK_LS -> RECEIVEPACK */
234 	//~ int function(git_smart_subtransport *transport) close;
235 
236 	//~ void function(git_smart_subtransport *transport) free;
237 //~ };
238 
239 //~ /* A function which creates a new subtransport for the smart transport */
240 //~ alias git_smart_subtransport_cb = int function(
241 	//~ git_smart_subtransport **out_,
242 	//~ git_transport* owner);
243 
244 //~ struct git_smart_subtransport_definition {
245 	//~ /* The function to use to create the git_smart_subtransport */
246 	//~ git_smart_subtransport_cb callback;
247 
248 	//~ /* True if the protocol is stateless; false otherwise. For example,
249 	 //~ * http:// is stateless, but git:// is not. */
250 	//~ uint rpc;
251 //~ } ;
252 
253 //~ /* Smart transport subtransports that come with libgit2 */
254 
255 //~ /**
256  //~ * Create an instance of the http subtransport. This subtransport
257  //~ * also supports https. On Win32, this subtransport may be implemented
258  //~ * using the WinHTTP library.
259  //~ *
260  //~ * @param out The newly created subtransport
261  //~ * @param owner The smart transport to own this subtransport
262  //~ * @return 0 or an error code
263  //~ */
264 //~ int git_smart_subtransport_http(
265 	//~ git_smart_subtransport **out_,
266 	//~ git_transport* owner);
267 
268 //~ /**
269  //~ * Create an instance of the git subtransport.
270  //~ *
271  //~ * @param out The newly created subtransport
272  //~ * @param owner The smart transport to own this subtransport
273  //~ * @return 0 or an error code
274  //~ */
275 //~ int git_smart_subtransport_git(
276 	//~ git_smart_subtransport **out_,
277 	//~ git_transport* owner);
278 
279 //~ /**
280  //~ * Create an instance of the ssh subtransport.
281  //~ *
282  //~ * @param out The newly created subtransport
283  //~ * @param owner The smart transport to own this subtransport
284  //~ * @return 0 or an error code
285  //~ */
286 //~ int git_smart_subtransport_ssh(
287 	//~ git_smart_subtransport **out_,
288 	//~ git_transport* owner);