From: claudio Date: Thu, 8 Apr 2021 16:46:59 +0000 (+0000) Subject: Shuffle deck chairs so that the order is more logical (at least for me). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=47d3b88a4338e0e8a9785bd3e02e5b3c17e6f986;p=openbsd Shuffle deck chairs so that the order is more logical (at least for me). No functional change. --- diff --git a/usr.sbin/rpki-client/http.c b/usr.sbin/rpki-client/http.c index 771265ec544..7b6aa68e383 100644 --- a/usr.sbin/rpki-client/http.c +++ b/usr.sbin/rpki-client/http.c @@ -1,4 +1,4 @@ -/* $OpenBSD: http.c,v 1.22 2021/04/08 16:43:08 claudio Exp $ */ +/* $OpenBSD: http.c,v 1.23 2021/04/08 16:46:59 claudio Exp $ */ /* * Copyright (c) 2020 Nils Fisher * Copyright (c) 2020 Claudio Jeker @@ -311,24 +311,6 @@ http_free(struct http_connection *conn) free(conn); } -static int -http_close(struct http_connection *conn) -{ - if (conn->tls != NULL) { - switch (tls_close(conn->tls)) { - case TLS_WANT_POLLIN: - return WANT_POLLIN; - case TLS_WANT_POLLOUT: - return WANT_POLLOUT; - case 0: - case -1: - break; - } - } - - return -1; -} - static int http_parse_uri(char *uri, char **ohost, char **oport, char **opath) { @@ -425,46 +407,6 @@ http_new(size_t id, char *uri, char *modified_since, int outfd) return conn; } -static int -http_redirect(struct http_connection *conn, char *uri) -{ - char *host, *port, *path; - - logx("redirect to %s", http_info(uri)); - - if (http_parse_uri(uri, &host, &port, &path) == -1) { - free(uri); - return -1; - } - - free(conn->url); - conn->url = uri; - free(conn->host); - conn->host = host; - free(conn->port); - conn->port = port; - conn->path = path; - /* keep modified_since since that is part of the request */ - free(conn->last_modified); - conn->last_modified = NULL; - free(conn->buf); - conn->buf = NULL; - conn->bufpos = 0; - conn->bufsz = 0; - tls_close(conn->tls); - tls_free(conn->tls); - conn->tls = NULL; - close(conn->fd); - conn->state = STATE_INIT; - - /* TODO proxy support (overload of host and port) */ - - if (http_resolv(conn, host, port) == -1) - return -1; - - return 0; -} - static int http_connect(struct http_connection *conn) { @@ -668,29 +610,6 @@ http_request(struct http_connection *conn) return WANT_POLLOUT; } -static int -http_write(struct http_connection *conn) -{ - ssize_t s; - - s = tls_write(conn->tls, conn->buf + conn->bufpos, - conn->bufsz - conn->bufpos); - if (s == -1) { - warnx("%s: TLS write: %s", http_info(conn->url), - tls_error(conn->tls)); - return -1; - } else if (s == TLS_WANT_POLLIN) { - return WANT_POLLIN; - } else if (s == TLS_WANT_POLLOUT) { - return WANT_POLLOUT; - } - - conn->bufpos += s; - if (conn->bufpos == conn->bufsz) - return 0; - return WANT_POLLOUT; -} - static int http_parse_status(struct http_connection *conn, char *buf) { @@ -748,6 +667,46 @@ http_isredirect(struct http_connection *conn) return 0; } +static int +http_redirect(struct http_connection *conn, char *uri) +{ + char *host, *port, *path; + + logx("redirect to %s", http_info(uri)); + + if (http_parse_uri(uri, &host, &port, &path) == -1) { + free(uri); + return -1; + } + + free(conn->url); + conn->url = uri; + free(conn->host); + conn->host = host; + free(conn->port); + conn->port = port; + conn->path = path; + /* keep modified_since since that is part of the request */ + free(conn->last_modified); + conn->last_modified = NULL; + free(conn->buf); + conn->buf = NULL; + conn->bufpos = 0; + conn->bufsz = 0; + tls_close(conn->tls); + tls_free(conn->tls); + conn->tls = NULL; + close(conn->fd); + conn->state = STATE_INIT; + + /* TODO proxy support (overload of host and port) */ + + if (http_resolv(conn, host, port) == -1) + return -1; + + return 0; +} + static int http_parse_header(struct http_connection *conn, char *buf) { @@ -964,6 +923,47 @@ http_read(struct http_connection *conn) } } +static int +http_write(struct http_connection *conn) +{ + ssize_t s; + + s = tls_write(conn->tls, conn->buf + conn->bufpos, + conn->bufsz - conn->bufpos); + if (s == -1) { + warnx("%s: TLS write: %s", http_info(conn->url), + tls_error(conn->tls)); + return -1; + } else if (s == TLS_WANT_POLLIN) { + return WANT_POLLIN; + } else if (s == TLS_WANT_POLLOUT) { + return WANT_POLLOUT; + } + + conn->bufpos += s; + if (conn->bufpos == conn->bufsz) + return 0; + return WANT_POLLOUT; +} + +static int +http_close(struct http_connection *conn) +{ + if (conn->tls != NULL) { + switch (tls_close(conn->tls)) { + case TLS_WANT_POLLIN: + return WANT_POLLIN; + case TLS_WANT_POLLOUT: + return WANT_POLLOUT; + case 0: + case -1: + break; + } + } + + return -1; +} + static int data_write(struct http_connection *conn) {