commit - 36162ed86d688a25773a4575c164f8b6ac08632b
commit + f890c8c54d88b529dc568eaf187b29a5acf6d22d
blob - de1d48e706711f1e0bf8cc55ce3ca3bce5d9b5cd
blob + 4a2c2c33e4efe3604fb6da45e59bae65bcc575e4
--- gmid.h
+++ gmid.h
void cgi_poll_on_client(struct pollfd*, struct client*);
void handle_cgi(struct pollfd*, struct client*);
void close_conn(struct pollfd*, struct client*);
+void goodbye(struct pollfd*, struct client*, int, const char*);
void do_accept(int, struct tls*, struct pollfd*, struct client*);
void handle(struct pollfd*, struct client*);
void loop(struct tls*, int, int);
blob - 13e2e7397be2c8397ea542ed23b4a7dc3555a89f
blob + 8337dcf388e3552cd08b25b422cd6fdfdbf4ec4e
--- server.c
+++ server.c
case FILE_MISSING:
if (c->host->cgi != NULL && starts_with(c->iri.path, c->host->cgi))
return check_for_cgi(c->iri.path, c->iri.query, fds, c);
-
- if (!start_reply(fds, c, NOT_FOUND, "not found"))
- return 0;
- close_conn(fds, c);
+ goodbye(fds, c, NOT_FOUND, "not found");
return 0;
default:
}
err:
- if (!start_reply(fds, c, NOT_FOUND, "not found"))
- return 0;
- close_conn(fds, c);
+ goodbye(fds, c, NOT_FOUND, "not found");
return 0;
}
else
strncpy(c->req, "null", sizeof(c->req));
- if (!start_reply(fds, c, BAD_REQUEST, "Wrong host or missing SNI"))
- return;
- close_conn(fds, c);
+ goodbye(fds, c, BAD_REQUEST, "Wrong host or missing SNI");
}
void
}
if (!trim_req_iri(c->req) || !parse_iri(c->req, &c->iri, &parse_err)) {
- if (!start_reply(fds, c, BAD_REQUEST, parse_err))
- return;
- close_conn(fds, c);
+ goodbye(fds, c, BAD_REQUEST, parse_err);
return;
}
/* XXX: we should check that the SNI matches the requested host */
if (strcmp(c->iri.schema, "gemini") || c->iri.port_no != conf.port) {
- if (!start_reply(fds, c, PROXY_REFUSED, "won't proxy request"))
- return;
- close_conn(fds, c);
+ goodbye(fds, c, PROXY_REFUSED, "won't proxy request");
return;
}
close(c->fd);
if ((c->fd = recv_fd(exfd)) == -1) {
- if (!start_reply(fds, c, TEMP_FAILURE, "internal server error"))
- return 0;
- close_conn(fds, c);
+ goodbye(fds, c, TEMP_FAILURE, "internal server error");
return 0;
}
c->child = 1;
* to foo/index.gmi
*/
if (c->iri.path == c->sbuf) {
- if (!start_reply(fds, c, TEMP_REDIRECT, c->sbuf))
- return;
- close_conn(fds, c);
+ goodbye(fds, c, TEMP_REDIRECT, c->sbuf);
return;
}
/* redirect to url with the trailing / */
strlcat(c->sbuf, c->iri.path, sizeof(c->sbuf));
strlcat(c->sbuf, "/", sizeof(c->sbuf));
- if (!start_reply(fds, c, TEMP_REDIRECT, c->sbuf))
- return;
- close_conn(fds, c);
+ goodbye(fds, c, TEMP_REDIRECT, c->sbuf);
return;
}
len = strlcat(c->sbuf, "index.gmi", sizeof(c->sbuf));
if (len >= sizeof(c->sbuf)) {
- if (!start_reply(fds, c, TEMP_FAILURE, "internal server error"))
- return;
- close_conn(fds, c);
+ goodbye(fds, c, TEMP_FAILURE, "internal server error");
return;
}
close(pfd->fd);
pfd->fd = -1;
+}
+
+void
+goodbye(struct pollfd *fds, struct client *c, int code, const char *meta)
+{
+ if (!start_reply(fds, c, code, meta))
+ return;
+ close_conn(fds, c);
}
void