Lines Matching defs:req

61 struct	req {
77 static void parse_manpath_conf(struct req *);
78 static void parse_path_info(struct req *, const char *);
79 static void parse_query_string(struct req *, const char *);
82 static void pg_index(const struct req *);
83 static void pg_noresult(const struct req *, int, const char *,
85 static void pg_redirect(const struct req *, const char *);
86 static void pg_search(const struct req *);
87 static void pg_searchres(const struct req *,
89 static void pg_show(struct req *, const char *);
92 static void resp_catman(const struct req *, const char *);
95 static void resp_format(const struct req *, const char *);
96 static void resp_searchform(const struct req *, enum focus);
97 static void resp_show(const struct req *, const char *);
101 static int validate_manpath(const struct req *, const char *);
206 parse_query_string(struct req *req, const char *qs)
211 req->isquery = 1;
212 req->q.manpath = NULL;
213 req->q.arch = NULL;
214 req->q.sec = NULL;
215 req->q.query = NULL;
216 req->q.equal = 1;
243 set_query_attr(&req->q.query, &val);
246 req->q.equal = !strcmp(val, "0");
256 set_query_attr(&req->q.manpath, &val);
266 set_query_attr(&req->q.sec, &val);
272 set_query_attr(&req->q.arch, &val);
435 resp_searchform(const struct req *req, enum focus focus)
449 if (req->q.query != NULL)
450 html_print(req->q.query);
469 if (NULL != req->q.sec &&
470 0 == strcmp(sec_numbers[i], req->q.sec))
480 if (NULL == req->q.arch)
485 if (NULL != req->q.arch &&
486 0 == strcmp(arch_names[i], req->q.arch))
494 if (req->psz > 1) {
497 for (i = 0; i < (int)req->psz; i++) {
499 if (strcmp(req->q.manpath, req->p[i]) == 0)
502 html_print(req->p[i]);
527 validate_manpath(const struct req *req, const char* manpath)
531 for (i = 0; i < req->psz; i++)
532 if ( ! strcmp(manpath, req->p[i]))
562 pg_index(const struct req *req)
566 resp_searchform(req, FOCUS_QUERY);
585 pg_noresult(const struct req *req, int code, const char *http_msg,
590 resp_searchform(req, FOCUS_QUERY);
626 pg_redirect(const struct req *req, const char *name)
632 if (strcmp(req->q.manpath, req->p[0]))
633 printf("%s/", req->q.manpath);
634 if (req->q.arch != NULL)
635 printf("%s/", req->q.arch);
637 if (req->q.sec != NULL) {
639 http_encode(req->q.sec);
645 pg_searchres(const struct req *req, struct manpage *r, size_t sz)
658 r[i].file, req->q.manpath);
663 if (req->isquery && sz == 1) {
672 if (strcmp(req->q.manpath, req->p[0]))
673 printf("%s/", req->q.manpath);
686 if (req->q.equal || sz == 1) {
697 if (req->q.arch == NULL) {
725 resp_searchform(req,
726 req->q.equal || sz == 1 ? FOCUS_NONE : FOCUS_QUERY);
738 if (strcmp(req->q.manpath, req->p[0]))
739 printf("%s/", req->q.manpath);
752 if (req->q.equal || sz == 1) {
754 resp_show(req, r[iuse].file);
761 resp_catman(const struct req *req, const char *file)
900 resp_format(const struct req *req, const char *file)
918 MPARSE_VALIDATE, MANDOC_OS_OTHER, req->q.manpath);
926 usepath = strcmp(req->q.manpath, req->p[0]);
929 usepath ? req->q.manpath : "", usepath ? "/" : "");
945 resp_show(const struct req *req, const char *file)
952 resp_catman(req, file);
954 resp_format(req, file);
958 pg_show(struct req *req, const char *fullpath)
971 if ( ! validate_manpath(req, manpath)) {
1000 resp_searchform(req, FOCUS_NONE);
1002 resp_show(req, file);
1007 pg_search(const struct req *req)
1023 if (chdir(req->q.manpath) == -1) {
1024 warn("chdir %s", req->q.manpath);
1029 search.arch = req->q.arch;
1030 search.sec = req->q.sec;
1032 search.argmode = req->q.equal ? ARG_NAME : ARG_EXPR;
1045 rp = query = mandoc_strdup(req->q.query);
1072 if (req->isquery && req->q.equal && argc == 1)
1073 pg_redirect(req, argv[0]);
1075 pg_noresult(req, 400, "Bad Request",
1078 pg_noresult(req, 404, "Not Found", "No results found.");
1080 pg_searchres(req, res, ressz);
1091 struct req req;
1137 memset(&req, 0, sizeof(struct req));
1138 req.q.equal = 1;
1139 parse_manpath_conf(&req);
1149 parse_path_info(&req, path);
1150 if (req.q.manpath == NULL || req.q.sec == NULL ||
1151 *req.q.query == '\0' || access(path, F_OK) == -1)
1154 parse_query_string(&req, querystring);
1158 if (req.q.manpath == NULL)
1159 req.q.manpath = mandoc_strdup(req.p[0]);
1160 else if ( ! validate_manpath(&req, req.q.manpath)) {
1166 if (req.q.arch != NULL && validate_arch(req.q.arch) == 0) {
1175 pg_show(&req, path);
1176 else if (NULL != req.q.query)
1177 pg_search(&req);
1179 pg_index(&req);
1181 free(req.q.manpath);
1182 free(req.q.arch);
1183 free(req.q.sec);
1184 free(req.q.query);
1185 for (i = 0; i < (int)req.psz; i++)
1186 free(req.p[i]);
1187 free(req.p);
1195 parse_path_info(struct req *req, const char *path)
1199 req->isquery = 0;
1200 req->q.equal = 1;
1201 req->q.manpath = NULL;
1202 req->q.arch = NULL;
1213 req->q.query = mandoc_strndup(name, sec - name - 1);
1214 req->q.sec = mandoc_strdup(sec);
1216 req->q.query = mandoc_strdup(name);
1217 req->q.sec = NULL;
1226 req->q.manpath = mandoc_strndup(path, end - path);
1227 if (validate_manpath(req, req->q.manpath)) {
1232 free(req->q.manpath);
1233 req->q.manpath = NULL;
1240 free(req->q.sec);
1241 req->q.sec = mandoc_strndup(path, end - path);
1254 req->q.arch = mandoc_strndup(path, end - path);
1255 if (validate_arch(req->q.arch) == 0) {
1266 parse_manpath_conf(struct req *req)
1285 req->p = mandoc_realloc(req->p,
1286 (req->psz + 1) * sizeof(char *));
1299 req->p[req->psz++] = dp;
1305 if (req->p == NULL) {