Lines Matching refs:req

57 struct	req {
72 static void parse_manpath_conf(struct req *);
73 static void parse_path_info(struct req *req, const char *path);
74 static void parse_query_string(struct req *, const char *);
77 static void pg_index(const struct req *);
78 static void pg_noresult(const struct req *, const char *);
79 static void pg_redirect(const struct req *, const char *);
80 static void pg_search(const struct req *);
81 static void pg_searchres(const struct req *,
83 static void pg_show(struct req *, const char *);
86 static void resp_catman(const struct req *, const char *);
89 static void resp_format(const struct req *, const char *);
90 static void resp_searchform(const struct req *, enum focus);
91 static void resp_show(const struct req *, const char *);
94 static int validate_manpath(const struct req *, const char *);
197 parse_query_string(struct req *req, const char *qs)
202 req->isquery = 1;
203 req->q.manpath = NULL;
204 req->q.arch = NULL;
205 req->q.sec = NULL;
206 req->q.query = NULL;
207 req->q.equal = 1;
234 set_query_attr(&req->q.query, &val);
237 req->q.equal = !strcmp(val, "0");
247 set_query_attr(&req->q.manpath, &val);
257 set_query_attr(&req->q.sec, &val);
263 set_query_attr(&req->q.arch, &val);
390 resp_searchform(const struct req *req, enum focus focus)
402 if (req->q.query != NULL)
403 html_print(req->q.query);
422 if (NULL != req->q.sec &&
423 0 == strcmp(sec_numbers[i], req->q.sec))
433 if (NULL == req->q.arch)
438 if (NULL != req->q.arch &&
439 0 == strcmp(arch_names[i], req->q.arch))
447 if (req->psz > 1) {
449 for (i = 0; i < (int)req->psz; i++) {
451 if (strcmp(req->q.manpath, req->p[i]) == 0)
454 html_print(req->p[i]);
456 html_print(req->p[i]);
481 validate_manpath(const struct req *req, const char* manpath)
485 for (i = 0; i < req->psz; i++)
486 if ( ! strcmp(manpath, req->p[i]))
504 pg_index(const struct req *req)
508 resp_searchform(req, FOCUS_QUERY);
522 pg_noresult(const struct req *req, const char *msg)
525 resp_searchform(req, FOCUS_QUERY);
555 pg_redirect(const struct req *req, const char *name)
561 if (strcmp(req->q.manpath, req->p[0]))
562 printf("%s/", req->q.manpath);
563 if (req->q.arch != NULL)
564 printf("%s/", req->q.arch);
566 if (req->q.sec != NULL)
567 printf(".%s", req->q.sec);
572 pg_searchres(const struct req *req, struct manpage *r, size_t sz)
584 r[i].file, req->q.manpath);
589 if (req->isquery && sz == 1) {
598 if (strcmp(req->q.manpath, req->p[0]))
599 printf("%s/", req->q.manpath);
612 if (req->q.equal || sz == 1) {
623 if (req->q.arch == NULL) {
649 resp_searchform(req,
650 req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY);
660 if (strcmp(req->q.manpath, req->p[0]))
661 printf("%s/", req->q.manpath);
673 if (req->q.equal || sz == 1) {
675 resp_show(req, r[iuse].file);
682 resp_catman(const struct req *req, const char *file)
819 resp_format(const struct req *req, const char *file)
835 MANDOCERR_MAX, NULL, MANDOC_OS_OTHER, req->q.manpath);
842 usepath = strcmp(req->q.manpath, req->p[0]);
845 usepath ? req->q.manpath : "", usepath ? "/" : "");
849 warnx("fatal mandoc error: %s/%s", req->q.manpath, file);
874 resp_show(const struct req *req, const char *file)
881 resp_catman(req, file);
883 resp_format(req, file);
887 pg_show(struct req *req, const char *fullpath)
900 if ( ! validate_manpath(req, manpath)) {
928 resp_searchform(req, FOCUS_NONE);
929 resp_show(req, file);
934 pg_search(const struct req *req)
950 if (chdir(req->q.manpath) == -1) {
951 warn("chdir %s", req->q.manpath);
956 search.arch = req->q.arch;
957 search.sec = req->q.sec;
959 search.argmode = req->q.equal ? ARG_NAME : ARG_EXPR;
972 rp = query = mandoc_strdup(req->q.query);
999 if (req->isquery && req->q.equal && argc == 1)
1000 pg_redirect(req, argv[0]);
1002 pg_noresult(req, "You entered an invalid query.");
1004 pg_noresult(req, "No results found.");
1006 pg_searchres(req, res, ressz);
1017 struct req req;
1063 memset(&req, 0, sizeof(struct req));
1064 req.q.equal = 1;
1065 parse_manpath_conf(&req);
1075 parse_path_info(&req, path);
1076 if (req.q.manpath == NULL || req.q.sec == NULL ||
1077 *req.q.query == '\0' || access(path, F_OK) == -1)
1080 parse_query_string(&req, querystring);
1084 if (req.q.manpath == NULL)
1085 req.q.manpath = mandoc_strdup(req.p[0]);
1086 else if ( ! validate_manpath(&req, req.q.manpath)) {
1092 if ( ! (NULL == req.q.arch || validate_urifrag(req.q.arch))) {
1101 pg_show(&req, path);
1102 else if (NULL != req.q.query)
1103 pg_search(&req);
1105 pg_index(&req);
1107 free(req.q.manpath);
1108 free(req.q.arch);
1109 free(req.q.sec);
1110 free(req.q.query);
1111 for (i = 0; i < (int)req.psz; i++)
1112 free(req.p[i]);
1113 free(req.p);
1121 parse_path_info(struct req *req, const char *path)
1126 req->isquery = 0;
1127 req->q.equal = 1;
1128 req->q.manpath = mandoc_strdup(path);
1129 req->q.arch = NULL;
1132 if ((req->q.query = strrchr(req->q.manpath, '/')) == NULL) {
1133 req->q.query = req->q.manpath;
1134 req->q.manpath = NULL;
1136 *req->q.query++ = '\0';
1139 if ((req->q.sec = strrchr(req->q.query, '.')) != NULL) {
1140 if(isdigit((unsigned char)req->q.sec[1])) {
1141 *req->q.sec++ = '\0';
1142 req->q.sec = mandoc_strdup(req->q.sec);
1144 req->q.sec = NULL;
1148 if (req->q.manpath == NULL)
1150 req->q.query = mandoc_strdup(req->q.query);
1153 dir[i = 0] = req->q.manpath;
1164 if ((i = validate_manpath(req, req->q.manpath)) == 0)
1165 req->q.manpath = NULL;
1171 free(req->q.sec);
1172 req->q.sec = mandoc_strdup(dir[i++] + 3);
1175 if (req->q.manpath == NULL)
1187 req->q.arch = mandoc_strdup(dir[i]);
1188 if (req->q.manpath == NULL)
1191 req->q.arch = dir[0];
1198 parse_manpath_conf(struct req *req)
1217 req->p = mandoc_realloc(req->p,
1218 (req->psz + 1) * sizeof(char *));
1231 req->p[req->psz++] = dp;
1237 if (req->p == NULL) {