[BACK]Return to cgi.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/cgi.c between version 1.177 and 1.178

version 1.177, 2022/07/04 16:20:42 version 1.178, 2022/07/05 14:04:25
Line 1 
Line 1 
 /* $Id$ */  /* $Id$ */
 /*  /*
  * Copyright (c) 2014-2019, 2021 Ingo Schwarze <schwarze@usta.de>   * Copyright (c) 2014-2019, 2021, 2022 Ingo Schwarze <schwarze@usta.de>
  * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2022 Anna Vyalkova <cyber@sysrq.in>   * Copyright (c) 2022 Anna Vyalkova <cyber@sysrq.in>
  *   *
Line 87  static void   pg_search(const struct req *);
Line 87  static void   pg_search(const struct req *);
 static  void             pg_searchres(const struct req *,  static  void             pg_searchres(const struct req *,
                                 struct manpage *, size_t);                                  struct manpage *, size_t);
 static  void             pg_show(struct req *, const char *);  static  void             pg_show(struct req *, const char *);
 static  void             resp_begin_html(int, const char *, const char *);  static  int              resp_begin_html(int, const char *, const char *);
 static  void             resp_begin_http(int, const char *);  static  void             resp_begin_http(int, const char *);
 static  void             resp_catman(const struct req *, const char *);  static  void             resp_catman(const struct req *, const char *);
 static  void             resp_copy(const char *);  static  int              resp_copy(const char *, const char *);
 static  void             resp_end_html(void);  static  void             resp_end_html(void);
 static  void             resp_format(const struct req *, const char *);  static  void             resp_format(const struct req *, const char *);
 static  void             resp_searchform(const struct req *, enum focus);  static  void             resp_searchform(const struct req *, enum focus);
Line 353  resp_begin_http(int code, const char *msg)
Line 353  resp_begin_http(int code, const char *msg)
         fflush(stdout);          fflush(stdout);
 }  }
   
 static void  static int
 resp_copy(const char *filename)  resp_copy(const char *element, const char *filename)
 {  {
         char     buf[4096];          char     buf[4096];
         ssize_t  sz;          ssize_t  sz;
         int      fd;          int      fd;
   
         if ((fd = open(filename, O_RDONLY)) != -1) {          if ((fd = open(filename, O_RDONLY)) == -1)
                 fflush(stdout);                  return 0;
                 while ((sz = read(fd, buf, sizeof(buf))) > 0)  
                         write(STDOUT_FILENO, buf, sz);          if (element != NULL)
                 close(fd);                  printf("<%s>\n", element);
         }          fflush(stdout);
           while ((sz = read(fd, buf, sizeof(buf))) > 0)
                   write(STDOUT_FILENO, buf, sz);
           close(fd);
           return 1;
 }  }
   
 static void  static int
 resp_begin_html(int code, const char *msg, const char *file)  resp_begin_html(int code, const char *msg, const char *file)
 {  {
         const char      *name, *sec, *cp;          const char      *name, *sec, *cp;
Line 414  resp_begin_html(int code, const char *msg, const char 
Line 418  resp_begin_html(int code, const char *msg, const char 
                "<body>\n",                 "<body>\n",
                CUSTOMIZE_TITLE);                 CUSTOMIZE_TITLE);
   
         resp_copy(MAN_DIR "/header.html");          return resp_copy("header", MAN_DIR "/header.html");
 }  }
   
 static void  static void
 resp_end_html(void)  resp_end_html(void)
 {  {
           if (resp_copy("footer", MAN_DIR "/footer.html"))
                   puts("</footer>");
   
         resp_copy(MAN_DIR "/footer.html");  
   
         puts("</body>\n"          puts("</body>\n"
              "</html>");               "</html>");
 }  }
Line 432  resp_searchform(const struct req *req, enum focus focu
Line 436  resp_searchform(const struct req *req, enum focus focu
 {  {
         int              i;          int              i;
   
         printf("<header>\n"          printf("<form role=\"search\" action=\"/%s\" method=\"get\" "
                "<form role=\"search\" action=\"/%s\" method=\"get\" "  
                "autocomplete=\"off\" autocapitalize=\"none\">\n"                 "autocomplete=\"off\" autocapitalize=\"none\">\n"
                "  <fieldset>\n"                 "  <fieldset>\n"
                "    <legend>Manual Page Search Parameters</legend>\n",                 "    <legend>Manual Page Search Parameters</legend>\n",
Line 501  resp_searchform(const struct req *req, enum focus focu
Line 504  resp_searchform(const struct req *req, enum focus focu
         }          }
   
         puts("  </fieldset>\n"          puts("  </fieldset>\n"
              "</form>\n"               "</form>");
              "</header>");  
 }  }
   
 static int  static int
Line 557  validate_filename(const char *file)
Line 559  validate_filename(const char *file)
 static void  static void
 pg_index(const struct req *req)  pg_index(const struct req *req)
 {  {
           if (resp_begin_html(200, NULL, NULL) == 0)
         resp_begin_html(200, NULL, NULL);                  puts("<header>");
         resp_searchform(req, FOCUS_QUERY);          resp_searchform(req, FOCUS_QUERY);
         printf("<main>\n"          printf("</header>\n"
                  "<main>\n"
                "<p role=\"doc-notice\" aria-label=\"usage\">\n"                 "<p role=\"doc-notice\" aria-label=\"usage\">\n"
                "This web interface is documented in the\n"                 "This web interface is documented in the\n"
                "<a class=\"Xr\" href=\"/%s%sman.cgi.8\""                 "<a class=\"Xr\" href=\"/%s%sman.cgi.8\""
Line 580  static void
Line 583  static void
 pg_noresult(const struct req *req, int code, const char *http_msg,  pg_noresult(const struct req *req, int code, const char *http_msg,
     const char *user_msg)      const char *user_msg)
 {  {
         resp_begin_html(code, http_msg, NULL);          if (resp_begin_html(code, http_msg, NULL) == 0)
                   puts("<header>");
         resp_searchform(req, FOCUS_QUERY);          resp_searchform(req, FOCUS_QUERY);
           puts("</header>");
         puts("<main>");          puts("<main>");
         puts("<p role=\"doc-notice\" aria-label=\"no result\">");          puts("<p role=\"doc-notice\" aria-label=\"no result\">");
         puts(user_msg);          puts(user_msg);
Line 593  pg_noresult(const struct req *req, int code, const cha
Line 598  pg_noresult(const struct req *req, int code, const cha
 static void  static void
 pg_error_badrequest(const char *msg)  pg_error_badrequest(const char *msg)
 {  {
           if (resp_begin_html(400, "Bad Request", NULL))
         resp_begin_html(400, "Bad Request", NULL);                  puts("</header>");
         puts("<main>\n"          puts("<main>\n"
              "<h1>Bad Request</h1>\n"               "<h1>Bad Request</h1>\n"
              "<p role=\"doc-notice\" aria-label=\"Bad Request\">");               "<p role=\"doc-notice\" aria-label=\"Bad Request\">");
Line 602  pg_error_badrequest(const char *msg)
Line 607  pg_error_badrequest(const char *msg)
         printf("Try again from the\n"          printf("Try again from the\n"
                "<a href=\"/%s\">main page</a>.\n"                 "<a href=\"/%s\">main page</a>.\n"
                "</p>\n"                 "</p>\n"
                "</main>", scriptname);                 "</main>\n", scriptname);
         resp_end_html();          resp_end_html();
 }  }
   
 static void  static void
 pg_error_internal(void)  pg_error_internal(void)
 {  {
         resp_begin_html(500, "Internal Server Error", NULL);          if (resp_begin_html(500, "Internal Server Error", NULL))
                   puts("</header>");
         puts("<main><p role=\"doc-notice\">Internal Server Error</p></main>");          puts("<main><p role=\"doc-notice\">Internal Server Error</p></main>");
         resp_end_html();          resp_end_html();
 }  }
Line 641  pg_searchres(const struct req *req, struct manpage *r,
Line 647  pg_searchres(const struct req *req, struct manpage *r,
         size_t           i, iuse;          size_t           i, iuse;
         int              archprio, archpriouse;          int              archprio, archpriouse;
         int              prio, priouse;          int              prio, priouse;
           int              have_header;
   
         for (i = 0; i < sz; i++) {          for (i = 0; i < sz; i++) {
                 if (validate_filename(r[i].file))                  if (validate_filename(r[i].file))
Line 707  pg_searchres(const struct req *req, struct manpage *r,
Line 714  pg_searchres(const struct req *req, struct manpage *r,
                         priouse = prio;                          priouse = prio;
                         iuse = i;                          iuse = i;
                 }                  }
                 resp_begin_html(200, NULL, r[iuse].file);                  have_header = resp_begin_html(200, NULL, r[iuse].file);
         } else          } else
                 resp_begin_html(200, NULL, NULL);                  have_header = resp_begin_html(200, NULL, NULL);
   
           if (have_header == 0)
                   puts("<header>");
         resp_searchform(req,          resp_searchform(req,
             req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY);              req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY);
           puts("</header>");
   
         if (sz > 1) {          if (sz > 1) {
                 puts("<nav>");                  puts("<nav>");
Line 983  pg_show(struct req *req, const char *fullpath)
Line 993  pg_show(struct req *req, const char *fullpath)
                 return;                  return;
         }          }
   
         resp_begin_html(200, NULL, file);          if (resp_begin_html(200, NULL, file) == 0)
                   puts("<header>");
         resp_searchform(req, FOCUS_NONE);          resp_searchform(req, FOCUS_NONE);
           puts("</header>");
         resp_show(req, file);          resp_show(req, file);
         resp_end_html();          resp_end_html();
 }  }

Legend:
Removed from v.1.177  
changed lines
  Added in v.1.178

CVSweb