- int i;
- const char *expr, *sec, *arch;
-
- expr = sec = arch = "";
-
- for (i = 0; i < (int)req->fieldsz; i++)
- if (0 == strcmp(req->fields[i].key, "expr"))
- expr = req->fields[i].val;
- else if (0 == strcmp(req->fields[i].key, "sec"))
- sec = req->fields[i].val;
- else if (0 == strcmp(req->fields[i].key, "arch"))
- arch = req->fields[i].val;
-
- puts("<!-- Begin search form. //-->");
- printf("<FORM ACTION=\"");
- html_print(progname);
- printf("/search.html\" METHOD=\"get\">\n");
- puts("<FIELDSET>\n"
- "<INPUT TYPE=\"submit\" NAME=\"op\" "
- "VALUE=\"Whatis\"> or \n"
- "<INPUT TYPE=\"submit\" NAME=\"op\" "
- "VALUE=\"apropos\"> for manuals satisfying \n"
- "<INPUT TYPE=\"text\" SIZE=\"40\" "
- "NAME=\"expr\" VALUE=\"");
- html_print(expr);
- puts("\">, section "
- "<INPUT TYPE=\"text\" "
- "SIZE=\"4\" NAME=\"sec\" VALUE=\"");
- html_print(sec);
- puts("\">, arch "
- "<INPUT TYPE=\"text\" "
- "SIZE=\"8\" NAME=\"arch\" VALUE=\"");
- html_print(arch);
- puts("\">.\n"
- "<INPUT TYPE=\"reset\" VALUE=\"Reset\">\n"
- "</FIELDSET>\n"
- "</FORM>\n"
- "<!-- End search form. //-->");
+ int i;
+
+ printf("<form action=\"/%s\" method=\"get\" "
+ "autocomplete=\"off\" autocapitalize=\"none\">\n"
+ " <fieldset>\n"
+ " <legend>Manual Page Search Parameters</legend>\n",
+ scriptname);
+
+ /* Write query input box. */
+
+ printf(" <input type=\"search\" 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");
+ 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(">");
+ html_print(req->p[i]);
+ puts("</option>");
+ }
+ puts(" </select>");
+ }
+
+ puts(" </fieldset>\n"
+ "</form>");
+}
+
+static int
+validate_urifrag(const char *frag)
+{
+
+ while ('\0' != *frag) {
+ if ( ! (isalnum((unsigned char)*frag) ||
+ '-' == *frag || '.' == *frag ||
+ '/' == *frag || '_' == *frag))
+ return 0;
+ frag++;
+ }
+ return 1;
+}
+
+static int
+validate_manpath(const struct req *req, const char* manpath)
+{
+ size_t i;
+
+ for (i = 0; i < req->psz; i++)
+ if ( ! strcmp(manpath, req->p[i]))
+ return 1;
+
+ return 0;
+}
+
+static int
+validate_arch(const char *arch)
+{
+ int i;
+
+ for (i = 0; i < arch_MAX; i++)
+ if (strcmp(arch, arch_names[i]) == 0)
+ return 1;
+
+ return 0;
+}
+
+static int
+validate_filename(const char *file)
+{
+
+ if ('.' == file[0] && '/' == file[1])
+ file += 2;
+
+ return ! (strstr(file, "../") || strstr(file, "/..") ||
+ (strncmp(file, "man", 3) && strncmp(file, "cat", 3)));