diff options
author | Michael Vogt <michael.vogt@ubuntu.com> | 2010-02-05 18:34:27 -0800 |
---|---|---|
committer | Michael Vogt <michael.vogt@ubuntu.com> | 2010-02-05 18:34:27 -0800 |
commit | bd49b02c03f09f9e7e76da8055f1364943b9dc57 (patch) | |
tree | 476e7b972b7f973dbe3cf9cacffda58596c2a5c7 /methods/http.cc | |
parent | c9cd3b70f3290071c79d7ef85ed87bd709a06bc6 (diff) |
add Acquire::http::ProxyAutoDetect configuration that
can be used to call a external helper to figure out the
proxy configuration and return it to apt via stdout
Diffstat (limited to 'methods/http.cc')
-rw-r--r-- | methods/http.cc | 49 |
1 files changed, 48 insertions, 1 deletions
diff --git a/methods/http.cc b/methods/http.cc index 2bd57024b..b05444691 100644 --- a/methods/http.cc +++ b/methods/http.cc @@ -1073,7 +1073,11 @@ bool HttpMethod::Configuration(string Message) PipelineDepth = _config->FindI("Acquire::http::Pipeline-Depth", PipelineDepth); Debug = _config->FindB("Debug::Acquire::http",false); - + AutoDetectProxyCmd = _config->Find("Acquire::http::ProxyAutoDetect"); + + // Get the proxy to use + AutoDetectProxy(); + return true; } /*}}}*/ @@ -1323,6 +1327,49 @@ int HttpMethod::Loop() return 0; } /*}}}*/ +// HttpMethod::AutoDetectProxy - auto detect proxy /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool HttpMethod::AutoDetectProxy() +{ + if (AutoDetectProxyCmd.empty()) + return true; + + if (Debug) + clog << "Using auto proxy detect command: " << AutoDetectProxyCmd << endl; + + int Pipes[2] = {-1,-1}; + if (pipe(Pipes) != 0) + return _error->Errno("pipe", "Failed to create Pipe"); + + pid_t Process = ExecFork(); + if (Process == 0) + { + dup2(Pipes[1],STDOUT_FILENO); + SetCloseExec(STDOUT_FILENO,false); + + const char *Args[2]; + Args[0] = AutoDetectProxyCmd.c_str(); + Args[1] = 0; + execv(Args[0],(char **)Args); + cerr << "Failed to exec method " << Args[0] << endl; + _exit(100); + } + char buf[512]; + int InFd = Pipes[0]; + if (read(InFd, buf, sizeof(buf)) < 0) + return _error->Errno("read", "Failed to read"); + ExecWait(Process, "ProxyAutoDetect"); + + if (Debug) + clog << "auto detect command returned: '" << buf << "'" << endl; + + if (strstr(buf, "http://") == buf) + _config->Set("Acquire::http::proxy", _strstrip(buf)); + + return true; +} + /*}}}*/ int main() { |