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 /**
8  * License: GPL-2.0(Linking Exception)
9  */
10 module libgit2.proxy;
11 
12 
13 private static import libgit2.cert;
14 private static import libgit2.credential;
15 private import libgit2.common: GIT_EXTERN;
16 
17 extern (C):
18 nothrow @nogc:
19 public:
20 
21 /**
22  * The type of proxy to use.
23  */
24 enum git_proxy_t
25 {
26 	/**
27 	 * Do not attempt to connect through a proxy
28 	 *
29 	 * If built against libcurl, it itself may attempt to connect
30 	 * to a proxy if the environment variables specify it.
31 	 */
32 	GIT_PROXY_NONE,
33 
34 	/**
35 	 * Try to auto-detect the proxy from the git configuration.
36 	 */
37 	GIT_PROXY_AUTO,
38 
39 	/**
40 	 * Connect via the URL given in the options
41 	 */
42 	GIT_PROXY_SPECIFIED,
43 }
44 
45 //Declaration name in C language
46 enum
47 {
48 	GIT_PROXY_NONE = .git_proxy_t.GIT_PROXY_NONE,
49 	GIT_PROXY_AUTO = .git_proxy_t.GIT_PROXY_AUTO,
50 	GIT_PROXY_SPECIFIED = .git_proxy_t.GIT_PROXY_SPECIFIED,
51 }
52 
53 /**
54  * Options for connecting through a proxy
55  *
56  * Note that not all types may be supported, depending on the platform
57  * and compilation options.
58  */
59 struct git_proxy_options
60 {
61 	uint version_;
62 
63 	/**
64 	 * The type of proxy to use, by URL, auto-detect.
65 	 */
66 	.git_proxy_t type;
67 
68 	/**
69 	 * The URL of the proxy.
70 	 */
71 	const (char)* url;
72 
73 	/**
74 	 * This will be called if the remote host requires
75 	 * authentication in order to connect to it.
76 	 *
77 	 * Returning git_error_code.GIT_PASSTHROUGH will make libgit2 behave as
78 	 * though this field isn't set.
79 	 */
80 	libgit2.credential.git_credential_acquire_cb credentials;
81 
82 	/**
83 	 * If cert verification fails, this will be called to let the
84 	 * user make the final decision of whether to allow the
85 	 * connection to proceed. Returns 0 to allow the connection
86 	 * or a negative value to indicate an error.
87 	 */
88 	libgit2.cert.git_transport_certificate_check_cb certificate_check;
89 
90 	/**
91 	 * Payload to be provided to the credentials and certificate
92 	 * check callbacks.
93 	 */
94 	void* payload;
95 }
96 
97 enum GIT_PROXY_OPTIONS_VERSION = 1;
98 
99 pragma(inline, true)
100 pure nothrow @safe @nogc @live
101 .git_proxy_options GIT_PROXY_OPTIONS_INIT()
102 
103 	do
104 	{
105 		.git_proxy_options OUTPUT =
106 		{
107 			version_: .GIT_PROXY_OPTIONS_VERSION,
108 		};
109 
110 		return OUTPUT;
111 	}
112 
113 /**
114  * Initialize git_proxy_options structure
115  *
116  * Initializes a `git_proxy_options` with default values. Equivalent to
117  * creating an instance with `GIT_PROXY_OPTIONS_INIT`.
118  *
119  * Params:
120  *      opts = The `git_proxy_options` struct to initialize.
121  *      version_ = The struct version; pass `GIT_PROXY_OPTIONS_VERSION`.
122  *
123  * Returns: Zero on success; -1 on failure.
124  */
125 @GIT_EXTERN
126 int git_proxy_options_init(.git_proxy_options* opts, uint version_);