Commit Diff


commit - 4f4937f06a536661ffafa589d1cfb5d91ca27bf3
commit + 47b0ff105a152b5f44bddaacc41318872370a222
blob - 147609e530110039497ee22a8721f3759cf2459c
blob + e3dfa8f4c0b0520bca9b8ab24f4ce5f2123ae450
--- gmid.c
+++ gmid.c
@@ -81,6 +81,63 @@ usage(void)
 	    getprogname());
 }
 
+/* used by the server process, defined here so gg can provide its own impl. */
+void
+log_request(struct client *c, char *meta, size_t l)
+{
+	char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV], b[GEMINI_URL_LEN];
+	char *fmted;
+	const char *t;
+	size_t len;
+	int ec;
+
+	len = sizeof(c->addr);
+	ec = getnameinfo((struct sockaddr*)&c->addr, len,
+	    hbuf, sizeof(hbuf),
+	    sbuf, sizeof(sbuf),
+	    NI_NUMERICHOST | NI_NUMERICSERV);
+	if (ec != 0)
+		fatalx("getnameinfo: %s", gai_strerror(ec));
+
+	if (c->iri.schema != NULL) {
+		/* serialize the IRI */
+		strlcpy(b, c->iri.schema, sizeof(b));
+		strlcat(b, "://", sizeof(b));
+
+		/* log the decoded host name, but if it was invalid
+		 * use the raw one. */
+		if (*c->domain != '\0')
+			strlcat(b, c->domain, sizeof(b));
+		else
+			strlcat(b, c->iri.host, sizeof(b));
+
+		if (*c->iri.path != '/')
+			strlcat(b, "/", sizeof(b));
+		strlcat(b, c->iri.path, sizeof(b)); /* TODO: sanitize UTF8 */
+		if (*c->iri.query != '\0') {	    /* TODO: sanitize UTF8 */
+			strlcat(b, "?", sizeof(b));
+			strlcat(b, c->iri.query, sizeof(b));
+		}
+	} else {
+		if ((t = c->req) == NULL)
+			t = "";
+		strlcpy(b, t, sizeof(b));
+	}
+
+	if ((t = memchr(meta, '\r', l)) == NULL)
+		t = meta + len;
+
+	ec = asprintf(&fmted, "%s:%s GET %s %.*s", hbuf, sbuf, b,
+	    (int)(t-meta), meta);
+	if (ec == -1)
+		err(1, "asprintf");
+
+	proc_compose(conf.ps, PROC_LOGGER, IMSG_LOG_REQUEST,
+	    fmted, ec + 1);
+
+	free(fmted);
+}
+
 static int
 write_pidfile(const char *pidfile)
 {
blob - 013f39168117946419a3fc4e60a3eb30251ea86f
blob + c7b1c4e761c949eb2f44002fdde6272f07a73b26
--- gmid.h
+++ gmid.h
@@ -328,6 +328,9 @@ enum imsg_type {
 char		*data_dir(void);
 void		 load_local_cert(struct vhost*, const char*, const char*);
 
+/* gmid.c / ge.c */
+void		 log_request(struct client *, char *, size_t);
+
 /* config.c */
 void		 config_init(void);
 void		 config_free(void);
blob - 08aa19e22d04a3f71463493492ee67f764717549
blob + 0460f76d9ed0bcc726b2cd25960a894a8684f953
--- logger.c
+++ logger.c
@@ -51,64 +51,6 @@ static struct privsep_proc procs[] = {
 };
 
 void
-log_request(struct client *c, char *meta, size_t l)
-{
-	char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV], b[GEMINI_URL_LEN];
-	char *fmted;
-	const char *t;
-	size_t len;
-	int ec;
-
-	len = sizeof(c->addr);
-	ec = getnameinfo((struct sockaddr*)&c->addr, len,
-	    hbuf, sizeof(hbuf),
-	    sbuf, sizeof(sbuf),
-	    NI_NUMERICHOST | NI_NUMERICSERV);
-	if (ec != 0)
-		fatalx("getnameinfo: %s", gai_strerror(ec));
-
-	if (c->iri.schema != NULL) {
-		/* serialize the IRI */
-		strlcpy(b, c->iri.schema, sizeof(b));
-		strlcat(b, "://", sizeof(b));
-
-		/* log the decoded host name, but if it was invalid
-		 * use the raw one. */
-		if (*c->domain != '\0')
-			strlcat(b, c->domain, sizeof(b));
-		else
-			strlcat(b, c->iri.host, sizeof(b));
-
-		if (*c->iri.path != '/')
-			strlcat(b, "/", sizeof(b));
-		strlcat(b, c->iri.path, sizeof(b)); /* TODO: sanitize UTF8 */
-		if (*c->iri.query != '\0') {	    /* TODO: sanitize UTF8 */
-			strlcat(b, "?", sizeof(b));
-			strlcat(b, c->iri.query, sizeof(b));
-		}
-	} else {
-		if ((t = c->req) == NULL)
-			t = "";
-		strlcpy(b, t, sizeof(b));
-	}
-
-	if ((t = memchr(meta, '\r', l)) == NULL)
-		t = meta + len;
-
-	ec = asprintf(&fmted, "%s:%s GET %s %.*s", hbuf, sbuf, b,
-	    (int)(t-meta), meta);
-	if (ec == -1)
-		err(1, "asprintf");
-
-	proc_compose(conf.ps, PROC_LOGGER, IMSG_LOG_REQUEST,
-	    fmted, ec + 1);
-
-	free(fmted);
-}
-
-
-
-void
 logger(struct privsep *ps, struct privsep_proc *p)
 {
 	proc_run(ps, p, procs, nitems(procs), logger_init, NULL);
blob - fb6a5061b1f5c86562affef69ceb5b866b06917c
blob + 59b92bcd28714fed26b71a44dfff682222e65bd9
--- logger.h
+++ logger.h
@@ -14,5 +14,4 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-void		 log_request(struct client *, char *, size_t);
 void		 logger(struct privsep *, struct privsep_proc *);