commit - dafb57b8af432d800219a8e17900e1ac56a65c14
commit + f7b816dc398efba2fb1cd4e2982ee3b23eed624f
blob - 6eed3f6f0eebe59619b009011f4be30440c13ee7
blob + f4948bdd04f578504bc3099318588705357c6a84
--- gmid.c
+++ gmid.c
} else {
len = sizeof(c->addr);
ec = getnameinfo((struct sockaddr*)&c->addr, len,
- hbuf, sizeof(hbuf),
- sbuf, sizeof(sbuf),
- NI_NUMERICHOST | NI_NUMERICSERV);
+ hbuf, sizeof(hbuf),
+ sbuf, sizeof(sbuf),
+ NI_NUMERICHOST | NI_NUMERICSERV);
if (ec != 0)
fatal("getnameinfo: %s", gai_strerror(ec));
}
int
start_reply(struct pollfd *pfd, struct client *client, int code, const char *reason)
{
- char buf[1030] = {0}; /* status + ' ' + max reply len + \r\n\0 */
+ char buf[1030]; /* status + ' ' + max reply len + \r\n\0 */
int len;
- int ret;
client->code = code;
client->meta = reason;
len = snprintf(buf, sizeof(buf), "%d %s\r\n", code, reason);
assert(len < (int)sizeof(buf));
- ret = tls_write(client->ctx, buf, len);
- if (ret == TLS_WANT_POLLIN) {
+
+ switch (tls_write(client->ctx, buf, len)) {
+ case TLS_WANT_POLLIN:
pfd->events = POLLIN;
return 0;
- }
-
- if (ret == TLS_WANT_POLLOUT) {
+ case TLS_WANT_POLLOUT:
pfd->events = POLLOUT;
return 0;
+ default:
+ return 1;
}
-
- return 1;
}
ssize_t
{
const char *end;
- end = path + strlen(path)-1; /* the last byte before the NUL */
+ end = path + strlen(path)-1;
for (; end != path; --end) {
if (*end == '.')
return end+1;
assert(path != NULL);
if ((*fd = openat(c->host->dirfd, *path ? path : ".",
- O_RDONLY | O_NOFOLLOW | O_CLOEXEC)) == -1) {
+ O_RDONLY | O_NOFOLLOW | O_CLOEXEC)) == -1) {
return FILE_MISSING;
}
goodbye(fds, c);
return 0;
}
-
int
open_file(char *fpath, char *query, struct pollfd *fds, struct client *c)
struct pollfd *fds, struct client *c)
{
pid_t pid;
- int p[2]; /* read end, write end */
+ int p[2]; /* read end, write end */
if (pipe(p) == -1)
goto err;
case -1:
goto err;
- case 0: { /* child */
+ case 0: { /* child */
char *ex, *requri, *portno;
char addr[NI_MAXHOST];
char *argv[] = { NULL, NULL, NULL };
goto childerr;
if (asprintf(&requri, "%s%s%s", spath,
- *relpath == '\0' ? "" : "/",
- relpath) == -1)
+ *relpath == '\0' ? "" : "/", relpath) == -1)
goto childerr;
argv[0] = argv[1] = ex;
servname = tls_conn_servername(c->ctx);
if (servname == NULL)
- goto wronghost;
+ goto hostnotfound;
for (h = hosts; h->domain != NULL; ++h) {
if (!strcmp(h->domain, servname) || !strcmp(h->domain, "*"))
return;
}
-wronghost:
+hostnotfound:
/* XXX: check the correct response */
if (!start_reply(fds, c, BAD_REQUEST, "Wrong host or missing SNI"))
return;
}
LOGI(c, "GET %s%s%s",
- *iri.path ? iri.path : "/",
- *iri.query ? "?" : "",
- *iri.query ? iri.query : "");
+ *iri.path ? iri.path : "/",
+ *iri.query ? "?" : "",
+ *iri.query ? iri.query : "");
send_file(iri.path, iri.query, fds, c);
}
void
goodbye(struct pollfd *pfd, struct client *c)
{
- ssize_t ret;
-
c->state = S_CLOSING;
- ret = tls_close(c->ctx);
- if (ret == TLS_WANT_POLLIN) {
+ switch (tls_close(c->ctx)) {
+ case TLS_WANT_POLLIN:
pfd->events = POLLIN;
return;
- }
- if (ret == TLS_WANT_POLLOUT) {
+ case TLS_WANT_POLLOUT:
pfd->events = POLLOUT;
return;
}
else
sock6 = -1;
-
if (!conf.foreground && daemon(0, 1) == -1)
exit(1);
blob - 3477cfefefdabc2af14d5ee18d930710a7c10588
blob + 9ef38a46788c3d80b8012d805bfcdf167551f5ec
--- gmid.h
+++ gmid.h
ssize_t len, off; /* mmap/static buffer */
int af;
struct sockaddr_storage addr;
- struct vhost *host; /* host he's talking to */
+ struct vhost *host; /* host she's talking to */
};
struct iri {
void usage(const char*);
+/* provided by lex/yacc */
extern FILE *yyin;
extern int yylineno;
extern int yyparse(void);
blob - d64afe8573d606eb389163efca65b27289baa17f
blob + 1e08e0f2fac1986ef47b1a1c4dcd39fdabecd204
--- iri.c
+++ iri.c
}
*p->iri = '\0';
- if (*(++p->iri) != '/' || *(++p->iri) != '/') {
+ if (p->iri[1] != '/' || p->iri[2] != '/') {
p->err = "invalid marker after scheme";
return 0;
}
- p->iri++;
+ p->iri += 3;
return 1;
}