示例#1
0
static void
html_printquery(const struct req *req)
{

	printf("&expr=");
	html_print(req->q.expr ? req->q.expr : "");
	printf("&sec=");
	html_print(req->q.sec ? req->q.sec : "");
	printf("&arch=");
	html_print(req->q.arch ? req->q.arch : "");
}
示例#2
0
static void
resp_searchform(const struct req *req)
{
	int		 i;

	puts("<!-- Begin search form. //-->");
	printf("<DIV ID=\"mancgi\">\n"
	       "<FORM ACTION=\"%s/search.html\" METHOD=\"get\">\n"
	       "<FIELDSET>\n"
	       "<LEGEND>Search Parameters</LEGEND>\n"
	       "<INPUT TYPE=\"submit\" "
	       " VALUE=\"Search\"> for manuals satisfying \n"
	       "<INPUT TYPE=\"text\" NAME=\"expr\" VALUE=\"",
	       progname);
	html_print(req->q.expr ? req->q.expr : "");
	printf("\">, section "
	       "<INPUT TYPE=\"text\""
	       " SIZE=\"4\" NAME=\"sec\" VALUE=\"");
	html_print(req->q.sec ? req->q.sec : "");
	printf("\">, arch "
	       "<INPUT TYPE=\"text\""
	       " SIZE=\"8\" NAME=\"arch\" VALUE=\"");
	html_print(req->q.arch ? req->q.arch : "");
	printf("\">");
	if (req->psz > 1) {
		puts(", <SELECT NAME=\"manpath\">");
		for (i = 0; i < (int)req->psz; i++) {
			printf("<OPTION %s VALUE=\"",
				(i == req->q.manroot) ||
				(0 == i && -1 == req->q.manroot) ?
				"SELECTED=\"selected\"" : "");
			html_print(req->p[i].name);
			printf("\">");
			html_print(req->p[i].name);
			puts("</OPTION>");
		}
		puts("</SELECT>");
	}
	puts(".\n"
	     "<INPUT TYPE=\"reset\" VALUE=\"Reset\">\n"
	     "</FIELDSET>\n"
	     "</FORM>\n"
	     "</DIV>");
	puts("<!-- End search form. //-->");
}
示例#3
0
static void
resp_error404(const char *page)
{

	resp_begin_html(404, "Not Found");
	puts("<H1>Page Not Found</H1>\n"
	     "<P>\n"
	     "The page you're looking for, ");
	printf("<B>");
	html_print(page);
	printf("</B>,\n"
	       "could not be found.\n"
	       "Try searching from the\n"
	       "<A HREF=\"%s/index.html\">main page</A>.\n"
	       "</P>", progname);
	resp_end_html();
}
示例#4
0
文件: cgi.c 项目: mr-justin/freebsd
static void
pg_searchres(const struct req *req, struct manpage *r, size_t sz)
{
	char		*arch, *archend;
	size_t		 i, iuse, isec;
	int		 archprio, archpriouse;
	int		 prio, priouse;
	char		 sec;

	for (i = 0; i < sz; i++) {
		if (validate_filename(r[i].file))
			continue;
		fprintf(stderr, "invalid filename %s in %s database\n",
		    r[i].file, req->q.manpath);
		pg_error_internal();
		return;
	}

	if (1 == sz) {
		/*
		 * If we have just one result, then jump there now
		 * without any delay.
		 */
		printf("Status: 303 See Other\r\n");
		printf("Location: http://%s%s/%s/%s?",
		    HTTP_HOST, scriptname, req->q.manpath, r[0].file);
		http_printquery(req, "&");
		printf("\r\n"
		     "Content-Type: text/html; charset=utf-8\r\n"
		     "\r\n");
		return;
	}

	resp_begin_html(200, NULL);
	resp_searchform(req);
	puts("<DIV CLASS=\"results\">");
	puts("<TABLE>");

	for (i = 0; i < sz; i++) {
		printf("<TR>\n"
		       "<TD CLASS=\"title\">\n"
		       "<A HREF=\"%s/%s/%s?", 
		    scriptname, req->q.manpath, r[i].file);
		http_printquery(req, "&amp;");
		printf("\">");
		html_print(r[i].names);
		printf("</A>\n"
		       "</TD>\n"
		       "<TD CLASS=\"desc\">");
		html_print(r[i].output);
		puts("</TD>\n"
		     "</TR>");
	}

	puts("</TABLE>\n"
	     "</DIV>");

	/*
	 * In man(1) mode, show one of the pages
	 * even if more than one is found.
	 */

	if (req->q.equal) {
		puts("<HR>");
		iuse = 0;
		priouse = 10;
		archpriouse = 3;
		for (i = 0; i < sz; i++) {
			isec = strcspn(r[i].file, "123456789");
			sec = r[i].file[isec];
			if ('\0' == sec)
				continue;
			prio = sec_prios[sec - '1'];
			if (NULL == req->q.arch) {
				archprio =
				    (NULL == (arch = strchr(
					r[i].file + isec, '/'))) ? 3 :
				    (NULL == (archend = strchr(
					arch + 1, '/'))) ? 0 :
				    strncmp(arch, "amd64/",
					archend - arch) ? 2 : 1;
				if (archprio < archpriouse) {
					archpriouse = archprio;
					priouse = prio;
					iuse = i;
					continue;
				}
				if (archprio > archpriouse)
					continue;
			}
			if (prio >= priouse)
				continue;
			priouse = prio;
			iuse = i;
		}
		resp_show(req, r[iuse].file);
	}

	resp_end_html();
}
示例#5
0
文件: cgi.c 项目: mr-justin/freebsd
static void
resp_searchform(const struct req *req)
{
	int		 i;

	puts(CUSTOMIZE_BEGIN);
	puts("<!-- Begin search form. //-->");
	printf("<DIV ID=\"mancgi\">\n"
	       "<FORM ACTION=\"%s\" METHOD=\"get\">\n"
	       "<FIELDSET>\n"
	       "<LEGEND>Manual Page Search Parameters</LEGEND>\n",
	       scriptname);

	/* Write query input box. */

	printf(	"<TABLE><TR><TD>\n"
		"<INPUT TYPE=\"text\" NAME=\"query\" VALUE=\"");
	if (NULL != req->q.query)
		html_print(req->q.query);
	puts("\" SIZE=\"40\">");

	/* Write submission and reset buttons. */

	printf(	"<INPUT TYPE=\"submit\" VALUE=\"Submit\">\n"
		"<INPUT TYPE=\"reset\" VALUE=\"Reset\">\n");

	/* Write show radio button */

	printf(	"</TD><TD>\n"
		"<INPUT TYPE=\"radio\" ");
	if (req->q.equal)
		printf("CHECKED=\"checked\" ");
	printf(	"NAME=\"apropos\" ID=\"show\" VALUE=\"0\">\n"
		"<LABEL FOR=\"show\">Show named manual page</LABEL>\n");

	/* Write section selector. */

	puts(	"</TD></TR><TR><TD>\n"
		"<SELECT NAME=\"sec\">");
	for (i = 0; i < sec_MAX; i++) {
		printf("<OPTION VALUE=\"%s\"", sec_numbers[i]);
		if (NULL != req->q.sec &&
		    0 == strcmp(sec_numbers[i], req->q.sec))
			printf(" SELECTED=\"selected\"");
		printf(">%s</OPTION>\n", sec_names[i]);
	}
	puts("</SELECT>");

	/* Write architecture selector. */

	printf(	"<SELECT NAME=\"arch\">\n"
		"<OPTION VALUE=\"default\"");
	if (NULL == req->q.arch)
		printf(" SELECTED=\"selected\"");
	puts(">All Architectures</OPTION>");
	for (i = 0; i < arch_MAX; i++) {
		printf("<OPTION VALUE=\"%s\"", arch_names[i]);
		if (NULL != req->q.arch &&
		    0 == strcmp(arch_names[i], req->q.arch))
			printf(" SELECTED=\"selected\"");
		printf(">%s</OPTION>\n", arch_names[i]);
	}
	puts("</SELECT>");

	/* Write manpath selector. */

	if (req->psz > 1) {
		puts("<SELECT NAME=\"manpath\">");
		for (i = 0; i < (int)req->psz; i++) {
			printf("<OPTION ");
			if (strcmp(req->q.manpath, req->p[i]) == 0)
				printf("SELECTED=\"selected\" ");
			printf("VALUE=\"");
			html_print(req->p[i]);
			printf("\">");
			html_print(req->p[i]);
			puts("</OPTION>");
		}
		puts("</SELECT>");
	}

	/* Write search radio button */

	printf(	"</TD><TD>\n"
		"<INPUT TYPE=\"radio\" ");
	if (0 == req->q.equal)
		printf("CHECKED=\"checked\" ");
	printf(	"NAME=\"apropos\" ID=\"search\" VALUE=\"1\">\n"
		"<LABEL FOR=\"search\">Search with apropos query</LABEL>\n");

	puts("</TD></TR></TABLE>\n"
	     "</FIELDSET>\n"
	     "</FORM>\n"
	     "</DIV>");
	puts("<!-- End search form. //-->");
}
示例#6
0
文件: cgi.c 项目: gokzy/netbsd-src
static void
pg_searchres(const struct req *req, struct manpage *r, size_t sz)
{
	char		*arch, *archend;
	const char	*sec;
	size_t		 i, iuse;
	int		 archprio, archpriouse;
	int		 prio, priouse;

	for (i = 0; i < sz; i++) {
		if (validate_filename(r[i].file))
			continue;
		warnx("invalid filename %s in %s database",
		    r[i].file, req->q.manpath);
		pg_error_internal();
		return;
	}

	if (req->isquery && sz == 1) {
		/*
		 * If we have just one result, then jump there now
		 * without any delay.
		 */
		printf("Status: 303 See Other\r\n");
		printf("Location: http://%s/%s%s%s/%s",
		    HTTP_HOST, scriptname,
		    *scriptname == '\0' ? "" : "/",
		    req->q.manpath, r[0].file);
		printf("\r\n"
		     "Content-Type: text/html; charset=utf-8\r\n"
		     "\r\n");
		return;
	}

	resp_begin_html(200, NULL);
	resp_searchform(req,
	    req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY);

	if (sz > 1) {
		puts("<div class=\"results\">");
		puts("<table>");

		for (i = 0; i < sz; i++) {
			printf("<tr>\n"
			       "<td class=\"title\">\n"
			       "<a href=\"/%s%s%s/%s",
			    scriptname, *scriptname == '\0' ? "" : "/",
			    req->q.manpath, r[i].file);
			printf("\">");
			html_print(r[i].names);
			printf("</a>\n"
			       "</td>\n"
			       "<td class=\"desc\">");
			html_print(r[i].output);
			puts("</td>\n"
			     "</tr>");
		}

		puts("</table>\n"
		     "</div>");
	}

	/*
	 * In man(1) mode, show one of the pages
	 * even if more than one is found.
	 */

	if (req->q.equal || sz == 1) {
		puts("<hr>");
		iuse = 0;
		priouse = 20;
		archpriouse = 3;
		for (i = 0; i < sz; i++) {
			sec = r[i].file;
			sec += strcspn(sec, "123456789");
			if (sec[0] == '\0')
				continue;
			prio = sec_prios[sec[0] - '1'];
			if (sec[1] != '/')
				prio += 10;
			if (req->q.arch == NULL) {
				archprio =
				    ((arch = strchr(sec + 1, '/'))
					== NULL) ? 3 :
				    ((archend = strchr(arch + 1, '/'))
					== NULL) ? 0 :
				    strncmp(arch, "amd64/",
					archend - arch) ? 2 : 1;
				if (archprio < archpriouse) {
					archpriouse = archprio;
					priouse = prio;
					iuse = i;
					continue;
				}
				if (archprio > archpriouse)
					continue;
			}
			if (prio >= priouse)
				continue;
			priouse = prio;
			iuse = i;
		}
		resp_show(req, r[iuse].file);
	}

	resp_end_html();
}
示例#7
0
文件: cgi.c 项目: gokzy/netbsd-src
static void
resp_searchform(const struct req *req, enum focus focus)
{
	int		 i;

	puts("<!-- Begin search form. //-->");
	printf("<div id=\"mancgi\">\n"
	       "<form action=\"/%s\" method=\"get\">\n"
	       "<fieldset>\n"
	       "<legend>Manual Page Search Parameters</legend>\n",
	       scriptname);

	/* Write query input box. */

	printf("<input type=\"text\" name=\"query\" value=\"");
	if (req->q.query != NULL)
		html_print(req->q.query);
	printf( "\" size=\"40\"");
	if (focus == FOCUS_QUERY)
		printf(" autofocus");
	puts(">");

	/* Write submission buttons. */

	printf(	"<button type=\"submit\" name=\"apropos\" value=\"0\">"
		"man</button>\n"
		"<button type=\"submit\" name=\"apropos\" value=\"1\">"
		"apropos</button>\n<br/>\n");

	/* Write section selector. */

	puts("<select name=\"sec\">");
	for (i = 0; i < sec_MAX; i++) {
		printf("<option value=\"%s\"", sec_numbers[i]);
		if (NULL != req->q.sec &&
		    0 == strcmp(sec_numbers[i], req->q.sec))
			printf(" selected=\"selected\"");
		printf(">%s</option>\n", sec_names[i]);
	}
	puts("</select>");

	/* Write architecture selector. */

	printf(	"<select name=\"arch\">\n"
		"<option value=\"default\"");
	if (NULL == req->q.arch)
		printf(" selected=\"selected\"");
	puts(">All Architectures</option>");
	for (i = 0; i < arch_MAX; i++) {
		printf("<option value=\"%s\"", arch_names[i]);
		if (NULL != req->q.arch &&
		    0 == strcmp(arch_names[i], req->q.arch))
			printf(" selected=\"selected\"");
		printf(">%s</option>\n", arch_names[i]);
	}
	puts("</select>");

	/* Write manpath selector. */

	if (req->psz > 1) {
		puts("<select name=\"manpath\">");
		for (i = 0; i < (int)req->psz; i++) {
			printf("<option ");
			if (strcmp(req->q.manpath, req->p[i]) == 0)
				printf("selected=\"selected\" ");
			printf("value=\"");
			html_print(req->p[i]);
			printf("\">");
			html_print(req->p[i]);
			puts("</option>");
		}
		puts("</select>");
	}

	puts("</fieldset>\n"
	     "</form>\n"
	     "</div>");
	puts("<!-- End search form. //-->");
}
示例#8
0
static void
resp_search(struct res *r, size_t sz, void *arg)
{
	size_t		 i, matched;
	const struct req *req;

	req = (const struct req *)arg;

	if (sz > 0)
		assert(req->q.manroot >= 0);

	for (matched = i = 0; i < sz; i++)
		if (r[i].matched)
			matched++;
	
	if (1 == matched) {
		for (i = 0; i < sz; i++)
			if (r[i].matched)
				break;
		/*
		 * If we have just one result, then jump there now
		 * without any delay.
		 */
		puts("Status: 303 See Other");
		printf("Location: http://%s%s/show/%d/%u/%u.html?",
				host, progname, req->q.manroot,
				r[i].volume, r[i].rec);
		http_printquery(req);
		puts("\n"
		     "Content-Type: text/html; charset=utf-8\n");
		return;
	}

	resp_begin_html(200, NULL);
	resp_searchform(req);

	puts("<DIV CLASS=\"results\">");

	if (0 == matched) {
		puts("<P>\n"
		     "No results found.\n"
		     "</P>\n"
		     "</DIV>");
		resp_end_html();
		return;
	}

	qsort(r, sz, sizeof(struct res), cmp);

	puts("<TABLE>");

	for (i = 0; i < sz; i++) {
		if ( ! r[i].matched)
			continue;
		printf("<TR>\n"
		       "<TD CLASS=\"title\">\n"
		       "<A HREF=\"%s/show/%d/%u/%u.html?", 
				progname, req->q.manroot,
				r[i].volume, r[i].rec);
		html_printquery(req);
		printf("\">");
		html_print(r[i].title);
		putchar('(');
		html_print(r[i].cat);
		if (r[i].arch && '\0' != *r[i].arch) {
			putchar('/');
			html_print(r[i].arch);
		}
		printf(")</A>\n"
		       "</TD>\n"
		       "<TD CLASS=\"desc\">");
		html_print(r[i].desc);
		puts("</TD>\n"
		     "</TR>");
	}

	puts("</TABLE>\n"
	     "</DIV>");
	resp_end_html();
}