Skip to content

Commit

Permalink
Merge branch 'master' into tmp-akash_rawal-stage3
Browse files Browse the repository at this point in the history
  • Loading branch information
akashrawal committed Sep 1, 2017
2 parents 688df4f + f73b251 commit 2c92388
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 22 deletions.
4 changes: 2 additions & 2 deletions libwget/http.c
Expand Up @@ -716,9 +716,9 @@ int wget_http_send_request(wget_http_connection_t *conn, wget_http_request_t *re
wget_vector_add_noalloc(conn->pending_requests, req);

if (req->debug_skip_body)
debug_printf("# sent %zd bytes:\n%.*s<body skipped>", nbytes, conn->buf->length - req->body_length, conn->buf->data);
debug_printf("# sent %zd bytes:\n%.*s<body skipped>", nbytes, (int)(conn->buf->length - req->body_length), conn->buf->data);
else
debug_printf("# sent %zd bytes:\n%.*s", nbytes, conn->buf->length, conn->buf->data);
debug_printf("# sent %zd bytes:\n%.*s", nbytes, (int)conn->buf->length, conn->buf->data);

return 0;
}
Expand Down
39 changes: 20 additions & 19 deletions src/wget.c
Expand Up @@ -132,15 +132,16 @@ static void
static long long
quota;
static int
exit_status,
hsts_changed,
hpkp_changed;
static unsigned int
exit_status;
static volatile int
terminate;
int
nthreads;

void set_exit_status(int status)
void set_exit_status(exit_status_t status)
{
// use Wget exit status scheme:
// - error code 0 is default
Expand Down Expand Up @@ -909,7 +910,7 @@ int main(int argc, const char **argv)

n = init(argc, argv);
if (n < 0) {
set_exit_status(1);
set_exit_status(WG_EXIT_STATUS_PARSE_INIT);
goto out;
}

Expand Down Expand Up @@ -1192,7 +1193,7 @@ static int establish_connection(DOWNLOADER *downloader, wget_iri_t **iri)
mirror_index = downloader->id % mirror_count;
else {
host_final_failure(downloader->job->host);
set_exit_status(1);
set_exit_status(WG_EXIT_STATUS_NETWORK);
return rc;
}

Expand Down Expand Up @@ -1225,7 +1226,7 @@ static int establish_connection(DOWNLOADER *downloader, wget_iri_t **iri)
// TLS failure
wget_http_close(&downloader->conn);
host_final_failure(downloader->job->host);
set_exit_status(5);
set_exit_status(WG_EXIT_STATUS_TLS);
}

return rc;
Expand Down Expand Up @@ -1264,9 +1265,9 @@ static int process_response_header(wget_http_response_t *resp)
// Wget1.x compatibility
if (resp->code/100 == 4 && resp->code!=416) {
if (job->head_first)
set_exit_status(8);
set_exit_status(WG_EXIT_STATUS_REMOTE);
else if (resp->code == 404 && !job->robotstxt)
set_exit_status(8);
set_exit_status(WG_EXIT_STATUS_REMOTE);
}

// Server doesn't support keep-alive or want us to close the connection.
Expand Down Expand Up @@ -1309,7 +1310,7 @@ static int process_response_header(wget_http_response_t *resp)
if (job->auth_failure_count > 1 || !resp->challenges) {
// We already tried with credentials and they are wrong OR
// The server sent no challenge. Don't try again.
set_exit_status(6);
set_exit_status(WG_EXIT_STATUS_AUTH);
return 1;
}

Expand All @@ -1323,7 +1324,7 @@ static int process_response_header(wget_http_response_t *resp)
if (job->proxy_challenges || !resp->challenges) {
// We already tried with credentials and they are wrong OR
// The proxy server sent no challenge. Don't try again.
set_exit_status(6);
set_exit_status(WG_EXIT_STATUS_AUTH);
return 1;
}

Expand Down Expand Up @@ -2545,7 +2546,7 @@ static int G_GNUC_WGET_NONNULL((1)) _prepare_file(wget_http_response_t *resp, co
size_t rc = safe_write(1, resp->header->data, resp->header->length);
if (rc == SAFE_WRITE_ERROR) {
error_printf(_("Failed to write to STDOUT (%zu, errno=%d)\n"), rc, errno);
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
}
}

Expand Down Expand Up @@ -2664,13 +2665,13 @@ static int G_GNUC_WGET_NONNULL((1)) _prepare_file(wget_http_response_t *resp, co
if (rc == SAFE_READ_ERROR || (long long) rc != size) {
error_printf(_("Failed to load partial content from '%s' (errno=%d): %s\n"),
fname, errno, strerror(errno));
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
}
close(fd);
} else {
error_printf(_("Failed to load partial content from '%s' (errno=%d): %s\n"),
fname, errno, strerror(errno));
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
}
}
}
Expand All @@ -2687,7 +2688,7 @@ static int G_GNUC_WGET_NONNULL((1)) _prepare_file(wget_http_response_t *resp, co
if (config.save_headers) {
if ((rc = write(fd, resp->header->data, resp->header->length)) != (ssize_t)resp->header->length) {
error_printf(_("Failed to write file %s (%zd, errno=%d)\n"), unique[0] ? unique : fname, rc, errno);
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
}
}
} else {
Expand All @@ -2698,7 +2699,7 @@ static int G_GNUC_WGET_NONNULL((1)) _prepare_file(wget_http_response_t *resp, co
info_printf(_("Directory / file name clash - not saving '%s'\n"), fname);
else {
error_printf(_("Failed to open '%s' (errno=%d): %s\n"), fname, errno, strerror(errno));
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
}
}
}
Expand All @@ -2711,7 +2712,7 @@ static int G_GNUC_WGET_NONNULL((1)) _prepare_file(wget_http_response_t *resp, co
fclose(fp);
} else {
error_printf(_("Failed to save extended attribute %s\n"), fname);
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
}
}

Expand Down Expand Up @@ -2751,13 +2752,13 @@ static int _get_header(wget_http_response_t *resp, void *context)
name = ctx->job->metalink->name;
ctx->outfd = open(ctx->job->metalink->name, O_WRONLY | O_CREAT | O_NONBLOCK | O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (ctx->outfd == -1) {
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
ret = -1;
goto out;
}
if (lseek(ctx->outfd, part->position, SEEK_SET) == (off_t) -1) {
close(ctx->outfd);
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
ret = -1;
goto out;
}
Expand Down Expand Up @@ -2828,7 +2829,7 @@ static int _get_body(wget_http_response_t *resp, void *context, const char *data
if (written == SAFE_WRITE_ERROR) {
if (!terminate)
error_printf(_("Failed to write errno=%d\n"), errno);
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
return -1;
}
}
Expand Down Expand Up @@ -3138,7 +3139,7 @@ wget_http_response_t *http_receive_response(wget_http_connection_t *conn)
if (config.fsync_policy) {
if (fsync(context->outfd) < 0 && errno == EIO) {
error_printf(_("Failed to fsync errno=%d\n"), errno);
set_exit_status(3);
set_exit_status(WG_EXIT_STATUS_IO);
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/wget_main.h
Expand Up @@ -61,7 +61,19 @@
// Number of threads in the program
extern int nthreads;

void set_exit_status(int status);
typedef enum exit_status_t {
WG_EXIT_STATUS_NO_ERROR = 0,
WG_EXIT_STATUS_GENERIC = 1,
WG_EXIT_STATUS_PARSE_INIT = 2,
WG_EXIT_STATUS_IO = 3,
WG_EXIT_STATUS_NETWORK = 4,
WG_EXIT_STATUS_TLS = 5,
WG_EXIT_STATUS_AUTH = 6,
WG_EXIT_STATUS_PROTOCOL = 7,
WG_EXIT_STATUS_REMOTE = 8,
} exit_status_t;

void set_exit_status(exit_status_t status);
const char * G_GNUC_WGET_NONNULL_ALL get_local_filename(wget_iri_t *iri);

#endif /* _WGET_WGET_H */

0 comments on commit 2c92388

Please sign in to comment.