source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Make all components of the URI individually optional,
Date: Mon, 11 Jul 2016 17:49:07 -0500 (EST)	[thread overview]
Message-ID: <6538843037991172865.enqueue@fantadrom.bsd.lv> (raw)

Log Message:
-----------
Make all components of the URI individually optional, 
independent of each other, as in: 
http://man.openbsd.org[/manpath][/mansec][/arch]/name[.sec]
The restrictions in the past kept confusing people.
Triggered by a question from RafaelNeves at gmail dot com.

Modified Files:
--------------
    mdocml:
        cgi.c
        man.cgi.8

Revision Data
-------------
Index: man.cgi.8
===================================================================
RCS file: /home/cvs/mdocml/mdocml/man.cgi.8,v
retrieving revision 1.19
retrieving revision 1.20
diff -Lman.cgi.8 -Lman.cgi.8 -u -p -r1.19 -r1.20
--- man.cgi.8
+++ man.cgi.8
@@ -252,7 +252,9 @@ and the name of the requested file, for 
 .Pa /OpenBSD-current/man1/mandoc.1 .
 This can be abbreviated according to the following syntax:
 .Sm off
-.Op / Ar manpath Oo / Cm man Ar sec Oc Op / Ar arch
+.Op / Ar manpath
+.Op / Cm man Ar sec
+.Op / Ar arch
 .Pf / Ar name Op \&. Ar sec
 .Sm on
 .It
Index: cgi.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/cgi.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -Lcgi.c -Lcgi.c -u -p -r1.134 -r1.135
--- cgi.c
+++ cgi.c
@@ -1064,11 +1064,13 @@ main(void)
 static void
 parse_path_info(struct req *req, const char *path)
 {
-	char	*dir;
+	char	*dir[4];
+	int	 i;
 
 	req->isquery = 0;
 	req->q.equal = 1;
 	req->q.manpath = mandoc_strdup(path);
+	req->q.arch = NULL;
 
 	/* Mandatory manual page name. */
 	if ((req->q.query = strrchr(req->q.manpath, '/')) == NULL) {
@@ -1087,27 +1089,50 @@ parse_path_info(struct req *req, const c
 	}
 
 	/* Handle the case of name[.section] only. */
-	if (req->q.manpath == NULL) {
-		req->q.arch = NULL;
+	if (req->q.manpath == NULL)
 		return;
-	}
 	req->q.query = mandoc_strdup(req->q.query);
 
-	/* Optional architecture. */
-	dir = strrchr(req->q.manpath, '/');
-	if (dir != NULL && strncmp(dir + 1, "man", 3) != 0) {
-		*dir++ = '\0';
-		req->q.arch = mandoc_strdup(dir);
-		dir = strrchr(req->q.manpath, '/');
-	} else
-		req->q.arch = NULL;
+	/* Split directory components. */
+	dir[i = 0] = req->q.manpath;
+	while ((dir[i + 1] = strchr(dir[i], '/')) != NULL) {
+		if (++i == 3) {
+			pg_error_badrequest(
+			    "You specified too many directory components.");
+			exit(EXIT_FAILURE);
+		}
+		*dir[i]++ = '\0';
+	}
+
+	/* Optional manpath. */
+	if ((i = validate_manpath(req, req->q.manpath)) == 0)
+		req->q.manpath = NULL;
+	else if (dir[1] == NULL)
+		return;
 
-	/* Optional directory name. */
-	if (dir != NULL && strncmp(dir + 1, "man", 3) == 0) {
-		*dir++ = '\0';
+	/* Optional section. */
+	if (strncmp(dir[i], "man", 3) == 0) {
 		free(req->q.sec);
-		req->q.sec = mandoc_strdup(dir + 3);
+		req->q.sec = mandoc_strdup(dir[i++] + 3);
 	}
+	if (dir[i] == NULL) {
+		if (req->q.manpath == NULL)
+			free(dir[0]);
+		return;
+	}
+	if (dir[i + 1] != NULL) {
+		pg_error_badrequest(
+		    "You specified an invalid directory component.");
+		exit(EXIT_FAILURE);
+	}
+
+	/* Optional architecture. */
+	if (i) {
+		req->q.arch = mandoc_strdup(dir[i]);
+		if (req->q.manpath == NULL)
+			free(dir[0]);
+	} else
+		req->q.arch = dir[0];
 }
 
 /*
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2016-07-11 22:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6538843037991172865.enqueue@fantadrom.bsd.lv \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).