version 1.83, 2014/07/25 16:07:13 |
version 1.84, 2014/07/25 16:43:37 |
Line 908 resp_show(const struct req *req, const char *file) |
|
Line 908 resp_show(const struct req *req, const char *file) |
|
} |
} |
|
|
static void |
static void |
pg_show(struct req *req, const char *path) |
pg_show(struct req *req, const char *fullpath) |
{ |
{ |
char *sub; |
char *manpath; |
|
const char *file; |
|
|
if (NULL == path || NULL == (sub = strchr(path, '/'))) { |
if ((file = strchr(fullpath, '/')) == NULL) { |
pg_error_badrequest( |
pg_error_badrequest( |
"You did not specify a page to show."); |
"You did not specify a page to show."); |
return; |
return; |
} |
} |
*sub++ = '\0'; |
manpath = mandoc_strndup(fullpath, file - fullpath); |
|
file++; |
|
|
if ( ! validate_manpath(req, path)) { |
if ( ! validate_manpath(req, manpath)) { |
pg_error_badrequest( |
pg_error_badrequest( |
"You specified an invalid manpath."); |
"You specified an invalid manpath."); |
|
free(manpath); |
return; |
return; |
} |
} |
|
|
Line 931 pg_show(struct req *req, const char *path) |
|
Line 934 pg_show(struct req *req, const char *path) |
|
* relative to the manpath root. |
* relative to the manpath root. |
*/ |
*/ |
|
|
if (-1 == chdir(path)) { |
if (chdir(manpath) == -1) { |
fprintf(stderr, "chdir %s: %s\n", |
fprintf(stderr, "chdir %s: %s\n", |
path, strerror(errno)); |
manpath, strerror(errno)); |
pg_error_internal(); |
pg_error_internal(); |
|
free(manpath); |
return; |
return; |
} |
} |
|
|
if ( ! validate_filename(sub)) { |
if (strcmp(manpath, "mandoc")) { |
|
free(req->q.manpath); |
|
req->q.manpath = manpath; |
|
} else |
|
free(manpath); |
|
|
|
if ( ! validate_filename(file)) { |
pg_error_badrequest( |
pg_error_badrequest( |
"You specified an invalid manual file."); |
"You specified an invalid manual file."); |
return; |
return; |
} |
} |
|
|
if (strcmp(path, "mandoc")) { |
|
free(req->q.manpath); |
|
req->q.manpath = mandoc_strdup(path); |
|
} |
|
|
|
resp_begin_html(200, NULL); |
resp_begin_html(200, NULL); |
resp_searchform(req); |
resp_searchform(req); |
resp_show(req, sub); |
resp_show(req, file); |
resp_end_html(); |
resp_end_html(); |
} |
} |
|
|