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 #ifndef INCLUDE_git_proxy_h__
8 #define INCLUDE_git_proxy_h__
9 
10 #include "common.h"
11 
12 #include "cert.h"
13 #include "credential.h"
14 
15 GIT_BEGIN_DECL
16 
17 /**
18  * The type of proxy to use.
19  */
20 typedef enum {
21 	/**
22 	 * Do not attempt to connect through a proxy
23 	 *
24 	 * If built against libcurl, it itself may attempt to connect
25 	 * to a proxy if the environment variables specify it.
26 	 */
27 	GIT_PROXY_NONE,
28 	/**
29 	 * Try to auto-detect the proxy from the git configuration.
30 	 */
31 	GIT_PROXY_AUTO,
32 	/**
33 	 * Connect via the URL given in the options
34 	 */
35 	GIT_PROXY_SPECIFIED,
36 } git_proxy_t;
37 
38 /**
39  * Options for connecting through a proxy
40  *
41  * Note that not all types may be supported, depending on the platform
42  * and compilation options.
43  */
44 typedef struct {
45 	unsigned int version;
46 
47 	/**
48 	 * The type of proxy to use, by URL, auto-detect.
49 	 */
50 	git_proxy_t type;
51 
52 	/**
53 	 * The URL of the proxy.
54 	 */
55 	const char *url;
56 
57 	/**
58 	 * This will be called if the remote host requires
59 	 * authentication in order to connect to it.
60 	 *
61 	 * Returning GIT_PASSTHROUGH will make libgit2 behave as
62 	 * though this field isn't set.
63 	 */
64 	git_credential_acquire_cb credentials;
65 
66 	/**
67 	 * If cert verification fails, this will be called to let the
68 	 * user make the final decision of whether to allow the
69 	 * connection to proceed. Returns 0 to allow the connection
70 	 * or a negative value to indicate an error.
71 	 */
72 	git_transport_certificate_check_cb certificate_check;
73 
74 	/**
75 	 * Payload to be provided to the credentials and certificate
76 	 * check callbacks.
77 	 */
78 	void *payload;
79 } git_proxy_options;
80 
81 #define GIT_PROXY_OPTIONS_VERSION 1
82 #define GIT_PROXY_OPTIONS_INIT {GIT_PROXY_OPTIONS_VERSION}
83 
84 /**
85  * Initialize git_proxy_options structure
86  *
87  * Initializes a `git_proxy_options` with default values. Equivalent to
88  * creating an instance with `GIT_PROXY_OPTIONS_INIT`.
89  *
90  * @param opts The `git_proxy_options` struct to initialize.
91  * @param version The struct version; pass `GIT_PROXY_OPTIONS_VERSION`.
92  * @return Zero on success; -1 on failure.
93  */
94 GIT_EXTERN(int) git_proxy_options_init(git_proxy_options *opts, unsigned int version);
95 
96 GIT_END_DECL
97 
98 #endif
99