Skip to content

Commit

Permalink
Restructured WriteCurlrc; write in alphabetical order.
Browse files Browse the repository at this point in the history
The restructuring is to make subsequent fixes easier to do and
understand.

The alphabetical order is a side effect of using a map.
  • Loading branch information
mvidner committed Apr 9, 2015
1 parent 08b9ba6 commit f198d9b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 38 deletions.
68 changes: 38 additions & 30 deletions src/modules/Proxy.ycp
Expand Up @@ -108,41 +108,49 @@ void WriteSysconfig() {
SCR::Write(.sysconfig.proxy, nil);
}

/*
* Escape backslash characters in .curlrc (bnc#331038)
* see also http://curl.haxx.se/docs/manpage.html#-K for escaping rules
*/
string EscapeForCurlrc(string s) {
return mergestring (splitstring(s, "\\"), "\\\\");
}

void WriteCurlrc() {
string proxyuser = nil;
if (user != "") {
user = EscapeForCurlrc(user); // FIXME this clobbers the master value
proxyuser = user;
if (pass != "") proxyuser = user + ":" + pass;
}

map<string, string> options = $[
"--proxy-user": proxyuser,
// bnc#305163
"--proxy": http
];

// proxy is used, write /root/.curlrc
// bugzilla #305163
if (enabled) {
/* Update /root/.curlrc */
string proxyuser = nil;
if (user != "") {
//Escape backslash characters in .curlrc (#331038)
user = mergestring (splitstring(user, "\\"), "\\\\");
proxyuser = user;
if (pass != "") proxyuser = user + ":" + pass;
}

// nil or real value
SCR::Write (add (.root.curlrc, "--proxy-user"), proxyuser);

// not 'nil', not empty
// bugzilla #305163
if (http != nil && size (http) > 0) {
SCR::Write (add (.root.curlrc, "--proxy"), http);
} else {
SCR::Write (add (.root.curlrc, "--proxy"), nil);
}

// only written value can have a comment
if (proxyuser != nil) {
SCR::Write (add (add (.root.curlrc, "--proxy-user"), "comment"), ChangedComment("proxy"));
// only when set, can have a comment
} else if (http != nil && size (http) > 0) {
SCR::Write (add (add (.root.curlrc, "--proxy"), "comment"), ChangedComment("proxy"));
}
boolean write_comment = true;
foreach(string option, string value, options, {
if (value == "") {
value = nil;
}

SCR::Write (add (.root.curlrc, option), value);

if (value != nil && write_comment) {
SCR::Write (add (add (.root.curlrc, option), "comment"),
ChangedComment("proxy"));
write_comment = false;
}
});
// proxy is not used, remove proxy-related settings
} else {
SCR::Write (add (.root.curlrc, "--proxy-user"), nil);
SCR::Write (add (.root.curlrc, "--proxy"), nil);
foreach(string option, string value, options, {
SCR::Write (add (.root.curlrc, option), nil);
});
}

SCR::Write(.root.curlrc, nil);
Expand Down
16 changes: 8 additions & 8 deletions testsuite/tests/ProxyWrite.out
Expand Up @@ -6,8 +6,8 @@ Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" nil true
Write .root.curlrc."--proxy" nil true
Write .root.curlrc."--proxy-user" nil true
Write .root.curlrc nil true
Return true
Dump Write: enabled
Expand All @@ -17,10 +17,10 @@ Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" nil true
Write .root.curlrc."--proxy" "proxy.example.org:3128" true
Execute .target.bash_output "/bin/date '+%x'" $["stdout":"2015-01-31\n"]
Write .root.curlrc."--proxy"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc."--proxy-user" nil true
Write .root.curlrc nil true
Return true
Dump Write: authenticated
Expand All @@ -30,10 +30,10 @@ Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" "User\\\\Domain:P" true
Write .root.curlrc."--proxy" "proxy.example.org:3128" true
Execute .target.bash_output "/bin/date '+%x'" $["stdout":"2015-01-31\n"]
Write .root.curlrc."--proxy-user"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc."--proxy"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc."--proxy-user" "User\\\\Domain:P" true
Write .root.curlrc nil true
Return true
Dump Write: ftp
Expand All @@ -43,8 +43,8 @@ Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "proxy.example.org:3128" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" nil true
Write .root.curlrc."--proxy" nil true
Write .root.curlrc."--proxy-user" nil true
Write .root.curlrc nil true
Return true
Dump Write: authenticated ftp
Expand All @@ -54,8 +54,8 @@ Write .sysconfig.proxy.HTTPS_PROXY "" true
Write .sysconfig.proxy.FTP_PROXY "proxy.example.org:3128" true
Write .sysconfig.proxy.NO_PROXY "localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" "U:P" true
Write .root.curlrc."--proxy" nil true
Write .root.curlrc."--proxy-user" "U:P" true
Execute .target.bash_output "/bin/date '+%x'" $["stdout":"2015-01-31\n"]
Write .root.curlrc."--proxy-user"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc nil true
Expand All @@ -67,9 +67,9 @@ Write .sysconfig.proxy.HTTPS_PROXY "proxy2.example.org:3128" true
Write .sysconfig.proxy.FTP_PROXY "proxy3.example.org:3128" true
Write .sysconfig.proxy.NO_PROXY "example.org,example.com,localhost" true
Write .sysconfig.proxy nil true
Write .root.curlrc."--proxy-user" "U:P" true
Write .root.curlrc."--proxy" "proxy1.example.org:3128" true
Execute .target.bash_output "/bin/date '+%x'" $["stdout":"2015-01-31\n"]
Write .root.curlrc."--proxy-user"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc."--proxy"."comment" "\n# Changed by YaST2 module proxy 2015-01-31\n" true
Write .root.curlrc."--proxy-user" "U:P" true
Write .root.curlrc nil true
Return true

0 comments on commit f198d9b

Please sign in to comment.