summaryrefslogtreecommitdiff
path: root/libfetch/ftp.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2021-07-16 10:22:42 +0300
committerTimo Teräs <timo.teras@iki.fi>2021-07-16 10:25:14 +0300
commitd909ebc25b23c0ccd698f161ab624c3cdc890e35 (patch)
tree8dcac9a3c3168a650c5a4719f75dcaec70211ac0 /libfetch/ftp.c
parentb2819a6d5a7d9fa1a6e96e7a4d5e034b7fb63ac0 (diff)
downloadapk-tools-d909ebc25b23c0ccd698f161ab624c3cdc890e35.tar.gz
apk-tools-d909ebc25b23c0ccd698f161ab624c3cdc890e35.tar.bz2
apk-tools-d909ebc25b23c0ccd698f161ab624c3cdc890e35.tar.xz
apk-tools-d909ebc25b23c0ccd698f161ab624c3cdc890e35.zip
libfetch: simplify code by merging protocol error handling branches
removes some code duplication
Diffstat (limited to 'libfetch/ftp.c')
-rw-r--r--libfetch/ftp.c35
1 files changed, 13 insertions, 22 deletions
diff --git a/libfetch/ftp.c b/libfetch/ftp.c
index d489559..8f9f04f 100644
--- a/libfetch/ftp.c
+++ b/libfetch/ftp.c
@@ -722,8 +722,8 @@ retry_mode:
}
break;
default:
- e = FTP_PROTOCOL_ERROR; /* XXX: error code should be prepared */
- goto ouch;
+ /* XXX: error code should be prepared */
+ goto protocol_error;
}
/*
@@ -736,33 +736,22 @@ retry_mode:
case FTP_LPASSIVE_MODE:
for (p = ln + 3; *p && !isdigit((unsigned char)*p); p++)
/* nothing */ ;
- if (!*p) {
- e = FTP_PROTOCOL_ERROR;
- goto ouch;
- }
+ if (!*p) goto protocol_error;
l = (e == FTP_PASSIVE_MODE ? 6 : 21);
for (i = 0; *p && i < l; i++, p++)
addr[i] = strtol(p, &p, 10);
- if (i < l) {
- e = FTP_PROTOCOL_ERROR;
- goto ouch;
- }
+ if (i < l) goto protocol_error;
break;
case FTP_EPASSIVE_MODE:
for (p = ln + 3; *p && *p != '('; p++)
/* nothing */ ;
- if (!*p) {
- e = FTP_PROTOCOL_ERROR;
- goto ouch;
- }
+ if (!*p) goto protocol_error;
++p;
if (sscanf(p, "%c%c%c%d%c", &addr[0], &addr[1], &addr[2],
&port, &addr[3]) != 5 ||
addr[0] != addr[1] ||
- addr[0] != addr[2] || addr[0] != addr[3]) {
- e = FTP_PROTOCOL_ERROR;
- goto ouch;
- }
+ addr[0] != addr[2] || addr[0] != addr[3])
+ goto protocol_error;
break;
case FTP_SYNTAX_ERROR:
if (verbose)
@@ -803,8 +792,8 @@ retry_mode:
}
break;
default:
- e = FTP_PROTOCOL_ERROR; /* XXX: error code should be prepared */
- break;
+ /* XXX: error code should be prepared */
+ goto protocol_error;
}
/* connect to data port */
@@ -907,8 +896,8 @@ retry_mode:
}
break;
default:
- e = FTP_PROTOCOL_ERROR; /* XXX: error code should be prepared */
- goto ouch;
+ /* XXX: error code should be prepared */
+ goto protocol_error;
}
if (e != FTP_OK)
goto ouch;
@@ -946,6 +935,8 @@ sysouch:
close(sd);
return (NULL);
+protocol_error:
+ e = FTP_PROTOCOL_ERROR;
ouch:
if (e != -1)
ftp_seterr(e);