Lines Matching +full:loongson +full:- +full:1 +full:c

1 /* $Id: cgi.c,v 1.181 2023/04/28 19:11:03 schwarze Exp $ */
3 * Copyright (c) 2014-2019, 2021, 2022 Ingo Schwarze <schwarze@usta.de>
4 * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Copyright (c) 2022 Anna Vyalkova <cyber@sysrq.in>
106 static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
108 "0", "1", "2", "3", "3p", "4", "5", "6", "7", "8", "9"
112 "1 - General Commands",
113 "2 - System Calls",
114 "3 - Library Functions",
115 "3p - Perl Library",
116 "4 - Device Drivers",
117 "5 - File Formats",
118 "6 - Games",
119 "7 - Miscellaneous Information",
120 "8 - System Manager\'s Manual",
121 "9 - Kernel Developer\'s Manual"
127 "hppa", "i386", "landisk", "loongson",
145 * This will pass non-ASCII straight to output: be warned!
148 html_putchar(char c) in html_putchar() argument
151 switch (c) { in html_putchar()
165 putchar((unsigned char)c); in html_putchar()
202 * Parse the QUERY_STRING for key-value pairs
211 req->isquery = 1; in parse_query_string()
212 req->q.manpath = NULL; in parse_query_string()
213 req->q.arch = NULL; in parse_query_string()
214 req->q.sec = NULL; in parse_query_string()
215 req->q.query = NULL; in parse_query_string()
216 req->q.equal = 1; in parse_query_string()
240 /* Handle key-value pairs. */ in parse_query_string()
243 set_query_attr(&req->q.query, &val); in parse_query_string()
246 req->q.equal = !strcmp(val, "0"); in parse_query_string()
251 val[7] = '-'; in parse_query_string()
252 if ('C' == val[8]) in parse_query_string()
253 val[8] = 'c'; in parse_query_string()
256 set_query_attr(&req->q.manpath, &val); in parse_query_string()
266 set_query_attr(&req->q.sec, &val); in parse_query_string()
272 set_query_attr(&req->q.arch, &val); in parse_query_string()
292 * HTTP-decode a string. The standard explanation is that this turns
293 * "%4e+foo" into "n foo" in the regular way. This is done in-place
301 int c; in http_decode() local
308 if ('\0' == (hex[0] = *(p + 1))) in http_decode()
310 if ('\0' == (hex[1] = *(p + 2))) in http_decode()
312 if (1 != sscanf(hex, "%x", &c)) in http_decode()
314 if ('\0' == c) in http_decode()
317 *q = (char)c; in http_decode()
324 return 1; in http_decode()
332 strchr("-._~", *p) == NULL) in http_encode()
346 printf("Content-Type: text/html; charset=utf-8\r\n" in resp_begin_http()
347 "Cache-Control: no-cache\r\n" in resp_begin_http()
348 "Content-Security-Policy: default-src 'none'; " in resp_begin_http()
349 "style-src 'self' 'unsafe-inline'\r\n" in resp_begin_http()
350 "Pragma: no-cache\r\n" in resp_begin_http()
363 if ((fd = open(filename, O_RDONLY)) == -1) in resp_copy()
372 return 1; in resp_copy()
386 " <meta charset=\"UTF-8\"/>\n" in resp_begin_html()
388 " content=\"width=device-width, initial-scale=1.0\">\n" in resp_begin_html()
395 name = cp == NULL ? file : cp + 1; in resp_begin_html()
397 namesz = cp == NULL ? strlen(name) : cp - name; in resp_begin_html()
399 if (cp != NULL && cp[1] != '0') { in resp_begin_html()
400 sec = cp + 1; in resp_begin_html()
402 } else if (name - file > 1) { in resp_begin_html()
403 for (cp = name - 2; cp >= file; cp--) { in resp_begin_html()
404 if (*cp < '1' || *cp > '9') in resp_begin_html()
407 secsz = name - cp - 1; in resp_begin_html()
414 fputs(" - ", stdout); in resp_begin_html()
449 if (req->q.query != NULL) in resp_searchform()
450 html_print(req->q.query); in resp_searchform()
460 " <button type=\"submit\" name=\"apropos\" value=\"1\">" in resp_searchform()
466 puts(" <select name=\"sec\" aria-label=\"Manual section\">"); in resp_searchform()
469 if (NULL != req->q.sec && in resp_searchform()
470 0 == strcmp(sec_numbers[i], req->q.sec)) in resp_searchform()
478 printf( " <select name=\"arch\" aria-label=\"CPU architecture\">\n" in resp_searchform()
480 if (NULL == req->q.arch) in resp_searchform()
485 if (NULL != req->q.arch && in resp_searchform()
486 0 == strcmp(arch_names[i], req->q.arch)) in resp_searchform()
494 if (req->psz > 1) { in resp_searchform()
496 " aria-label=\"Manual path\">"); in resp_searchform()
497 for (i = 0; i < (int)req->psz; i++) { in resp_searchform()
499 if (strcmp(req->q.manpath, req->p[i]) == 0) in resp_searchform()
502 html_print(req->p[i]); in resp_searchform()
518 '-' == *frag || '.' == *frag || in validate_urifrag()
523 return 1; in validate_urifrag()
531 for (i = 0; i < req->psz; i++) in validate_manpath()
532 if ( ! strcmp(manpath, req->p[i])) in validate_manpath()
533 return 1; in validate_manpath()
545 return 1; in validate_arch()
554 if ('.' == file[0] && '/' == file[1]) in validate_filename()
569 "<p role=\"doc-notice\" aria-label=\"Usage\">\n" in pg_index()
572 " aria-label=\"man dot CGI, section 8\">man.cgi(8)</a>\n" in pg_index()
574 "<a class=\"Xr\" href=\"/%s%sapropos.1\"" in pg_index()
575 " aria-label=\"apropos, section 1\">apropos(1)</a>\n" in pg_index()
593 puts("<p role=\"doc-notice\" aria-label=\"No result\">"); in pg_noresult()
607 "<p role=\"doc-notice\" aria-label=\"Bad Request\">"); in pg_error_badrequest()
621 puts("<main><p role=\"doc-notice\">Internal Server Error</p></main>"); in pg_error_internal()
632 if (strcmp(req->q.manpath, req->p[0])) in pg_redirect()
633 printf("%s/", req->q.manpath); in pg_redirect()
634 if (req->q.arch != NULL) in pg_redirect()
635 printf("%s/", req->q.arch); in pg_redirect()
637 if (req->q.sec != NULL) { in pg_redirect()
639 http_encode(req->q.sec); in pg_redirect()
641 printf("\r\nContent-Type: text/html; charset=utf-8\r\n\r\n"); in pg_redirect()
658 r[i].file, req->q.manpath); in pg_searchres()
663 if (req->isquery && sz == 1) { in pg_searchres()
672 if (strcmp(req->q.manpath, req->p[0])) in pg_searchres()
673 printf("%s/", req->q.manpath); in pg_searchres()
675 "Content-Type: text/html; charset=utf-8\r\n\r\n", in pg_searchres()
681 * In man(1) mode, show one of the pages in pg_searchres()
686 if (req->q.equal || sz == 1) { in pg_searchres()
694 prio = sec_prios[sec[0] - '1']; in pg_searchres()
695 if (sec[1] != '/') in pg_searchres()
697 if (req->q.arch == NULL) { in pg_searchres()
699 ((arch = strchr(sec + 1, '/')) in pg_searchres()
701 ((archend = strchr(arch + 1, '/')) in pg_searchres()
704 archend - arch) ? 2 : 1; in pg_searchres()
726 req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY); in pg_searchres()
729 if (sz > 1) { in pg_searchres()
738 if (strcmp(req->q.manpath, req->p[0])) in pg_searchres()
739 printf("%s/", req->q.manpath); in pg_searchres()
752 if (req->q.equal || sz == 1) { in pg_searchres()
771 puts("<p role=\"doc-notice\">\n" in resp_catman()
783 while ((len = getline(&p, &sz, f)) != -1) { in resp_catman()
785 for (i = 0; i < len - 1; i++) { in resp_catman()
798 * If we're in back-space mode, make sure we'll in resp_catman()
802 if ('\b' != p[i + 1]) { in resp_catman()
821 italic = 1; in resp_catman()
828 * Handle funny behaviour troff-isms. in resp_catman()
829 * These grok'd from the original man2html.c. in resp_catman()
848 } else if (('|' == p[i] && '-' == p[i + 2]) || in resp_catman()
849 ('-' == p[i] && '|' == p[i + 1]) || in resp_catman()
850 ('+' == p[i] && '-' == p[i + 1]) || in resp_catman()
851 ('-' == p[i] && '+' == p[i + 1]) || in resp_catman()
852 ('+' == p[i] && '|' == p[i + 1]) || in resp_catman()
853 ('|' == p[i] && '+' == p[i + 1])) { in resp_catman()
870 bold = 1; in resp_catman()
886 if (i == len - 1 && p[i] != '\n') in resp_catman()
909 if (-1 == (fd = open(file, O_RDONLY))) { in resp_format()
910 puts("<p role=\"doc-notice\">\n" in resp_format()
918 MPARSE_VALIDATE, MANDOC_OS_OTHER, req->q.manpath); in resp_format()
924 conf.fragment = 1; in resp_format()
926 usepath = strcmp(req->q.manpath, req->p[0]); in resp_format()
929 usepath ? req->q.manpath : "", usepath ? "/" : ""); in resp_format()
932 if (meta->macroset == MACROSET_MDOC) in resp_format()
948 if ('.' == file[0] && '/' == file[1]) in resp_show()
951 if ('c' == *file) in resp_show()
968 manpath = mandoc_strndup(fullpath, file - fullpath); in pg_show()
984 if (chdir(manpath) == -1) { in pg_show()
1023 if (chdir(req->q.manpath) == -1) { in pg_search()
1024 warn("chdir %s", req->q.manpath); in pg_search()
1029 search.arch = req->q.arch; in pg_search()
1030 search.sec = req->q.sec; in pg_search()
1032 search.argmode = req->q.equal ? ARG_NAME : ARG_EXPR; in pg_search()
1033 search.firstmatch = 1; in pg_search()
1035 paths.sz = 1; in pg_search()
1040 * Break apart at spaces with backslash-escaping. in pg_search()
1045 rp = query = mandoc_strdup(req->q.query); in pg_search()
1051 argv = mandoc_reallocarray(argv, argc + 1, sizeof(char *)); in pg_search()
1059 if (rp[0] == '\\' && rp[1] != '\0') in pg_search()
1072 if (req->isquery && req->q.equal && argc == 1) in pg_search()
1103 * pledge() calls in multiple low-level resp_*() functions. in main()
1106 if (pledge("stdio rpath", NULL) == -1) { in main()
1119 if (setitimer(ITIMER_VIRTUAL, &itimer, NULL) == -1) { in main()
1131 if (chdir(MAN_DIR) == -1) { in main()
1138 req.q.equal = 1; in main()
1151 *req.q.query == '\0' || access(path, F_OK) == -1) in main()
1199 req->isquery = 0; in parse_path_info()
1200 req->q.equal = 1; in parse_path_info()
1201 req->q.manpath = NULL; in parse_path_info()
1202 req->q.arch = NULL; in parse_path_info()
1213 req->q.query = mandoc_strndup(name, sec - name - 1); in parse_path_info()
1214 req->q.sec = mandoc_strdup(sec); in parse_path_info()
1216 req->q.query = mandoc_strdup(name); in parse_path_info()
1217 req->q.sec = NULL; in parse_path_info()
1226 req->q.manpath = mandoc_strndup(path, end - path); in parse_path_info()
1227 if (validate_manpath(req, req->q.manpath)) { in parse_path_info()
1228 path = end + 1; in parse_path_info()
1232 free(req->q.manpath); in parse_path_info()
1233 req->q.manpath = NULL; in parse_path_info()
1240 free(req->q.sec); in parse_path_info()
1241 req->q.sec = mandoc_strndup(path, end - path); in parse_path_info()
1242 path = end + 1; in parse_path_info()
1249 if (end + 1 != name) { in parse_path_info()
1254 req->q.arch = mandoc_strndup(path, end - path); in parse_path_info()
1255 if (validate_arch(req->q.arch) == 0) { in parse_path_info()
1282 while ((len = getline(&dp, &dpsz, fp)) != -1) { in parse_manpath_conf()
1283 if (dp[len - 1] == '\n') in parse_manpath_conf()
1284 dp[--len] = '\0'; in parse_manpath_conf()
1285 req->p = mandoc_realloc(req->p, in parse_manpath_conf()
1286 (req->psz + 1) * sizeof(char *)); in parse_manpath_conf()
1299 req->p[req->psz++] = dp; in parse_manpath_conf()
1305 if (req->p == NULL) { in parse_manpath_conf()