commit - 42bbdc7978acc6be9beb5baa7d94fedb7c211b49
commit + 36162ed86d688a25773a4575c164f8b6ac08632b
blob - 488ade6d2b5427987ee355ceb7694beaca5bb68e
blob + de1d48e706711f1e0bf8cc55ce3ca3bce5d9b5cd
--- gmid.h
+++ gmid.h
void cgi_poll_on_child(struct pollfd*, struct client*);
void cgi_poll_on_client(struct pollfd*, struct client*);
void handle_cgi(struct pollfd*, struct client*);
-void goodbye(struct pollfd*, struct client*);
+void close_conn(struct pollfd*, struct client*);
void do_accept(int, struct tls*, struct pollfd*, struct client*);
void handle(struct pollfd*, struct client*);
void loop(struct tls*, int, int);
blob - 2d80dcb8ace35260868d88c4fef3f5177a92ae67
blob + 13e2e7397be2c8397ea542ed23b4a7dc3555a89f
--- server.c
+++ server.c
case FILE_EXISTS:
if ((c->len = filesize(c->fd)) == -1) {
LOGE(c, "failed to get file size for %s", c->iri.path);
- goodbye(fds, c);
+ close_conn(fds, c);
return 0;
}
if ((c->buf = mmap(NULL, c->len, PROT_READ, MAP_PRIVATE,
c->fd, 0)) == MAP_FAILED) {
LOGW(c, "mmap: %s: %s", c->iri.path, strerror(errno));
- goodbye(fds, c);
+ close_conn(fds, c);
return 0;
}
c->i = c->buf;
if (!start_reply(fds, c, NOT_FOUND, "not found"))
return 0;
- goodbye(fds, c);
+ close_conn(fds, c);
return 0;
default:
err:
if (!start_reply(fds, c, NOT_FOUND, "not found"))
return 0;
- goodbye(fds, c);
+ close_conn(fds, c);
return 0;
}
if (!start_reply(fds, c, BAD_REQUEST, "Wrong host or missing SNI"))
return;
- goodbye(fds, c);
+ close_conn(fds, c);
}
void
switch (tls_read(c->ctx, c->req, sizeof(c->req)-1)) {
case -1:
LOGE(c, "tls_read: %s", tls_error(c->ctx));
- goodbye(fds, c);
+ close_conn(fds, c);
return;
case TLS_WANT_POLLIN:
if (!trim_req_iri(c->req) || !parse_iri(c->req, &c->iri, &parse_err)) {
if (!start_reply(fds, c, BAD_REQUEST, parse_err))
return;
- goodbye(fds, c);
+ close_conn(fds, c);
return;
}
if (strcmp(c->iri.schema, "gemini") || c->iri.port_no != conf.port) {
if (!start_reply(fds, c, PROXY_REFUSED, "won't proxy request"))
return;
- goodbye(fds, c);
+ close_conn(fds, c);
return;
}
if ((c->fd = recv_fd(exfd)) == -1) {
if (!start_reply(fds, c, TEMP_FAILURE, "internal server error"))
return 0;
- goodbye(fds, c);
+ close_conn(fds, c);
return 0;
}
c->child = 1;
switch (ret = tls_write(c->ctx, c->i, len)) {
case -1:
LOGE(c, "tls_write: %s", tls_error(c->ctx));
- goodbye(fds, c);
+ close_conn(fds, c);
return;
case TLS_WANT_POLLIN:
}
}
- goodbye(fds, c);
+ close_conn(fds, c);
}
void
if (c->iri.path == c->sbuf) {
if (!start_reply(fds, c, TEMP_REDIRECT, c->sbuf))
return;
- goodbye(fds, c);
+ close_conn(fds, c);
return;
}
strlcat(c->sbuf, "/", sizeof(c->sbuf));
if (!start_reply(fds, c, TEMP_REDIRECT, c->sbuf))
return;
- goodbye(fds, c);
+ close_conn(fds, c);
return;
}
if (len >= sizeof(c->sbuf)) {
if (!start_reply(fds, c, TEMP_FAILURE, "internal server error"))
return;
- goodbye(fds, c);
+ close_conn(fds, c);
return;
}
}
end:
- goodbye(fds, c);
+ close_conn(fds, c);
}
void
-goodbye(struct pollfd *pfd, struct client *c)
+close_conn(struct pollfd *pfd, struct client *c)
{
c->state = S_CLOSING;
if (client->code != SUCCESS) {
/* we don't need a body */
- goodbye(fds, client);
+ close_conn(fds, client);
return;
}
break;
case S_CLOSING:
- goodbye(fds, client);
+ close_conn(fds, client);
break;
default:
/* fds[i] may be the fd of the stdin
* of a cgi script that has exited. */
if (!clients[i].waiting_on_child) {
- goodbye(&fds[i], &clients[i]);
+ close_conn(&fds[i], &clients[i]);
continue;
}
}