url: handle exceptional cases first in parse_url_login()

Instead of nesting "if(success)" blocks and leaving the reader in
suspense about what happens in the !success case, deal with failure
cases early, usually with a simple goto to clean up and return from
the function.

No functional change intended.  The main effect is to decrease the
indentation of this function slightly.
This commit is contained in:
Jonathan Nieder
2013-08-19 01:01:26 -07:00
committed by Daniel Stenberg
parent 15f76bf7bb
commit 09ddb1d61c

View File

@@ -4460,12 +4460,12 @@ static CURLcode parse_url_login(struct SessionHandle *data,
passwd[0] = 0;
options[0] = 0;
if(!ptr)
goto out;
/* We will now try to extract the
* possible login information in a string like:
* ftp://user:password@ftp.my.site:8021/README */
if(ptr) {
/* There's login information to the left of the @ */
conn->host.name = ++ptr;
/* So the hostname is sane. Only bother interpreting the
@@ -4474,11 +4474,15 @@ static CURLcode parse_url_login(struct SessionHandle *data,
* set user/passwd, but doing that first adds more cases here :-(
*/
if(data->set.use_netrc != CURL_NETRC_REQUIRED) {
if(data->set.use_netrc == CURL_NETRC_REQUIRED)
goto out;
/* We could use the login information in the URL so extract it */
result = parse_login_details(login, ptr - login - 1,
&userp, &passwdp, &optionsp);
if(!result) {
if(result != CURLE_OK)
goto out;
if(userp) {
char *newname;
@@ -4489,10 +4493,8 @@ static CURLcode parse_url_login(struct SessionHandle *data,
/* Decode the user */
newname = curl_easy_unescape(data, userp, 0, NULL);
if(!newname) {
Curl_safefree(userp);
Curl_safefree(passwdp);
Curl_safefree(optionsp);
return CURLE_OUT_OF_MEMORY;
result = CURLE_OUT_OF_MEMORY;
goto out;
}
if(strlen(newname) < MAX_CURL_USER_LENGTH)
@@ -4505,10 +4507,8 @@ static CURLcode parse_url_login(struct SessionHandle *data,
/* We have a password in the URL so decode it */
char *newpasswd = curl_easy_unescape(data, passwdp, 0, NULL);
if(!newpasswd) {
Curl_safefree(userp);
Curl_safefree(passwdp);
Curl_safefree(optionsp);
return CURLE_OUT_OF_MEMORY;
result = CURLE_OUT_OF_MEMORY;
goto out;
}
if(strlen(newpasswd) < MAX_CURL_PASSWORD_LENGTH)
@@ -4521,10 +4521,8 @@ static CURLcode parse_url_login(struct SessionHandle *data,
/* We have an options list in the URL so decode it */
char *newoptions = curl_easy_unescape(data, optionsp, 0, NULL);
if(!newoptions) {
Curl_safefree(userp);
Curl_safefree(passwdp);
Curl_safefree(optionsp);
return CURLE_OUT_OF_MEMORY;
result = CURLE_OUT_OF_MEMORY;
goto out;
}
if(strlen(newoptions) < MAX_CURL_OPTIONS_LENGTH)
@@ -4532,13 +4530,12 @@ static CURLcode parse_url_login(struct SessionHandle *data,
free(newoptions);
}
}
out:
Curl_safefree(userp);
Curl_safefree(passwdp);
Curl_safefree(optionsp);
}
}
return result;
}