Commit Diff


commit - dafb57b8af432d800219a8e17900e1ac56a65c14
commit + f7b816dc398efba2fb1cd4e2982ee3b23eed624f
blob - 6eed3f6f0eebe59619b009011f4be30440c13ee7
blob + f4948bdd04f578504bc3099318588705357c6a84
--- gmid.c
+++ gmid.c
@@ -103,9 +103,9 @@ logs(int priority, struct client *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));
 	}
@@ -147,9 +147,8 @@ starts_with(const char *str, const char *prefix)
 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;
@@ -157,18 +156,17 @@ start_reply(struct pollfd *pfd, struct client *client,
 
 	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
@@ -188,7 +186,7 @@ path_ext(const char *path)
 {
 	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;
@@ -222,7 +220,7 @@ check_path(struct client *c, const char *path, int *fd
 
 	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;
 	}
 
@@ -282,7 +280,6 @@ err:
 	goodbye(fds, c);
 	return 0;
 }
-
 
 int
 open_file(char *fpath, char *query, struct pollfd *fds, struct client *c)
@@ -337,7 +334,7 @@ start_cgi(const char *spath, const char *relpath, cons
     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;
@@ -346,7 +343,7 @@ start_cgi(const char *spath, const char *relpath, cons
 	case -1:
 		goto err;
 
-	case 0: { 		/* child */
+	case 0: {		/* child */
 		char *ex, *requri, *portno;
 		char addr[NI_MAXHOST];
 		char *argv[] = { NULL, NULL, NULL };
@@ -373,8 +370,7 @@ start_cgi(const char *spath, const char *relpath, cons
 			goto childerr;
 
 		if (asprintf(&requri, "%s%s%s", spath,
-		    *relpath == '\0' ? "" : "/",
-		    relpath) == -1)
+		    *relpath == '\0' ? "" : "/", relpath) == -1)
 			goto childerr;
 
 		argv[0] = argv[1] = ex;
@@ -591,7 +587,7 @@ handle_handshake(struct pollfd *fds, struct client *c)
 
 	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, "*"))
@@ -605,7 +601,7 @@ handle_handshake(struct pollfd *fds, struct client *c)
 		return;
 	}
 
-wronghost:
+hostnotfound:
 	/* XXX: check the correct response */
 	if (!start_reply(fds, c, BAD_REQUEST, "Wrong host or missing SNI"))
 		return;
@@ -651,9 +647,9 @@ handle_open_conn(struct pollfd *fds, struct client *c)
 	}
 
 	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);
 }
@@ -810,16 +806,13 @@ do_accept(int sock, struct tls *ctx, struct pollfd *fd
 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;
 	}
@@ -1092,7 +1085,6 @@ main(int argc, char **argv)
 	else
 		sock6 = -1;
 
-
 	if (!conf.foreground && daemon(0, 1) == -1)
 		exit(1);
 
blob - 3477cfefefdabc2af14d5ee18d930710a7c10588
blob + 9ef38a46788c3d80b8012d805bfcdf167551f5ec
--- gmid.h
+++ gmid.h
@@ -92,7 +92,7 @@ struct client {
 	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 {
@@ -155,6 +155,7 @@ void		 load_vhosts(struct tls_config*);
 
 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
@@ -97,12 +97,12 @@ parse_scheme(struct parser *p)
 	}
 
 	*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;
 }