Skip to content

Commit 1b54575

Browse files
feat: get proxy via new proxy-lookup.exe for git-update
Signed-off-by: Roger Meier <[email protected]>
1 parent 2a45176 commit 1b54575

File tree

8 files changed

+89
-2
lines changed

8 files changed

+89
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*.swp
22
/ReleaseNotes.html
33
edit-git-bash.exe
4+
proxy-lookup.exe
45
/cached-source-packages/
56
/download-stats.ids
67
/git-extra/pkg/

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
CFLAGS=-O2 -Wall
22

3-
all: edit-git-bash.exe
3+
all: edit-git-bash.exe proxy-lookup.exe
44

55
edit-git-bash.exe: edit-git-bash.c
66
gcc -DSTANDALONE_EXE $(CFLAGS) -o $@ $^
7+
8+
proxy-lookup.exe: proxy-lookup.c
9+
gcc $(CFLAGS) -Werror -o $@ $^ -lshell32 -lwinhttp

git-extra/PKGBUILD

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ sha256sums=('e6a17a669fe8282792b3d98a2c47718425364a0ca9a456bdbad4a69c57ec6978'
6060
'2dba0f5f8133b8e8d1da8291efec140cd516e385f04b33b95e4f97fc40f628b3'
6161
'f4e310c00721f8834949268167b0584b7c9323775a318574dbca960af10d7998'
6262
'89b4d784e1c07d67c11a35abc7094709c216372e2099b2eb7abbc6eb7c34861f'
63-
'33a49036a52442a9754240e67abeb9dc2f686e8e25e5f70d522d78a150085e0a')
63+
'3bdbf7f37f4310c5169b2bfa7e6f3998ce1082ce97749f387ff5d72af87f63de')
6464

6565
prepare() {
6666
test $startdir/$pkgname.install -nt $startdir/$pkgname.install.in &&

git-extra/git-update

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
# when confirmation to do so is given.
66

77
git_update () {
8+
proxy=$(proxy-lookup https://api.github.com | grep URL | awk '{ print $4}' | awk -F";" '{print $1}')
9+
if test "$proxy" != ""
10+
then
11+
https_proxy="http://$proxy"
12+
echo "Using proxy server $https_proxy detected from Internet Explorer settings"
13+
fi
14+
815
yn=
916
while test $# -gt 0
1017
do

installer/install.iss

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ Source: {#SourcePath}\ReleaseNotes.html; DestDir: {app}; Flags: replacesameversi
118118
Source: {#SourcePath}\..\LICENSE.txt; DestDir: {app}; Flags: replacesameversion; AfterInstall: DeleteFromVirtualStore
119119
Source: {#SourcePath}\NOTICE.txt; DestDir: {app}; Flags: replacesameversion; AfterInstall: DeleteFromVirtualStore; Check: ParamIsSet('VSNOTICE')
120120
Source: {#SourcePath}\..\edit-git-bash.exe; Flags: dontcopy
121+
Source: {#SourcePath}\..\proxy-lookup.exe; DestDir: {app}\{#MINGW_BITNESS}\bin; Flags: replacesameversion
121122

122123
[Dirs]
123124
Name: "{app}\tmp"

installer/release.sh

+4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ echo "Compiling edit-git-bash.exe ..."
9696
make -C ../ edit-git-bash.exe ||
9797
die "Could not build edit-git-bash.exe"
9898

99+
# Compile proxy-lookup.exe
100+
make -C ../ proxy-lookup.exe ||
101+
die "Could not build proxy-lookup.exe."
102+
99103
if test t = "$skip_files"
100104
then
101105
LIST=

msi/release.sh

+4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ die "Could not generate ReleaseNotes.html."
124124
make -C ../ edit-git-bash.exe ||
125125
die "Could not build edit-git-bash.exe."
126126

127+
# Compile proxy-lookup.exe
128+
make -C ../ proxy-lookup.exe ||
129+
die "Could not build proxy-lookup.exe."
130+
127131
# Make a list of files to include
128132
LIST="$(ARCH=$ARCH BITNESS=$BITNESS \
129133
PACKAGE_VERSIONS_FILE="$SCRIPT_PATH"/package-versions.txt \

proxy-lookup.c

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// based on the sample provided here: https://github.com/git-for-windows/git/issues/387
2+
// probably inspired by https://msdn.microsoft.com/en-us/library/aa384122(v=vs.85).aspx
3+
4+
#include <stdio.h>
5+
#define WIN32_LEAN_AND_MEAN
6+
#include <windows.h>
7+
#include <winhttp.h>
8+
#include <shellapi.h>
9+
10+
LPCWSTR get_proxy_for_url(LPCWSTR url)
11+
{
12+
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG config;
13+
WINHTTP_AUTOPROXY_OPTIONS options;
14+
WINHTTP_PROXY_INFO info;
15+
16+
memset(&config, 0, sizeof(config));
17+
18+
if (!WinHttpGetIEProxyConfigForCurrentUser(&config))
19+
config.fAutoDetect = FALSE;
20+
else if (config.lpszAutoConfigUrl)
21+
config.fAutoDetect = TRUE;
22+
23+
if (config.fAutoDetect) {
24+
HINTERNET handle = WinHttpOpen(L"Proxy Lookup/1.0",
25+
WINHTTP_ACCESS_TYPE_NO_PROXY,
26+
WINHTTP_NO_PROXY_NAME,
27+
WINHTTP_NO_PROXY_BYPASS, 0);
28+
29+
memset(&options, 0, sizeof(options));
30+
31+
// use pac file URL from IE proxy configuration
32+
options.lpszAutoConfigUrl = config.lpszAutoConfigUrl;
33+
34+
options.fAutoLogonIfChallenged = TRUE;
35+
options.dwFlags = options.lpszAutoConfigUrl ?
36+
WINHTTP_AUTOPROXY_CONFIG_URL :
37+
WINHTTP_AUTOPROXY_AUTO_DETECT;
38+
if (!options.lpszAutoConfigUrl)
39+
options.dwAutoDetectFlags =
40+
WINHTTP_AUTO_DETECT_TYPE_DHCP |
41+
WINHTTP_AUTO_DETECT_TYPE_DNS_A;
42+
43+
config.fAutoDetect = WinHttpGetProxyForUrl(handle, url,
44+
&options, &info );
45+
46+
WinHttpCloseHandle(handle);
47+
}
48+
49+
if (config.fAutoDetect)
50+
return info.lpszProxy;
51+
return config.lpszProxy;
52+
}
53+
54+
int main(int argc, char **argv)
55+
{
56+
LPWSTR *wargv;
57+
int i, wargc;
58+
59+
wargv = CommandLineToArgvW(GetCommandLineW(), &wargc);
60+
wprintf(L"Proxy lookup\n");
61+
62+
for (i = 1; i < wargc; i++)
63+
wprintf(L"URL: %s, proxy: %s\n",
64+
wargv[i], get_proxy_for_url(wargv[i]));
65+
66+
return 0;
67+
}

0 commit comments

Comments
 (0)