mirror of https://github.com/omar-polo/gmid.git
fix PATH_INFO / SCRIPT_NAME splitting
This commit is contained in:
parent
03d671e2aa
commit
a1e159c917
35
fcgi.c
35
fcgi.c
|
@ -374,37 +374,43 @@ void
|
||||||
fcgi_req(struct client *c, struct location *loc)
|
fcgi_req(struct client *c, struct location *loc)
|
||||||
{
|
{
|
||||||
char buf[22], path[GEMINI_URL_LEN];
|
char buf[22], path[GEMINI_URL_LEN];
|
||||||
char *qs, *p, *pathinfo, *scriptname = NULL;
|
char *scriptname, *qs;
|
||||||
|
const char *stripped;
|
||||||
size_t l;
|
size_t l;
|
||||||
time_t tim;
|
time_t tim;
|
||||||
struct tm tminfo;
|
struct tm tminfo;
|
||||||
struct envlist *p;
|
struct envlist *p;
|
||||||
|
|
||||||
|
fcgi_begin_request(c->cgibev);
|
||||||
|
|
||||||
|
scriptname = "";
|
||||||
TAILQ_FOREACH(p, &loc->params, envs) {
|
TAILQ_FOREACH(p, &loc->params, envs) {
|
||||||
if (!strcmp(p->name, "SCRIPT_NAME")) {
|
if (!strcmp(p->name, "SCRIPT_NAME")) {
|
||||||
scriptname = p->value;
|
scriptname = p->value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (scriptname == NULL)
|
|
||||||
scriptname = "";
|
|
||||||
|
|
||||||
p = strip_path(c->iri.path, loc->fcgi_strip);
|
stripped = strip_path(c->iri.path, loc->fcgi_strip);
|
||||||
if (*p != '/')
|
if (*stripped != '/')
|
||||||
snprintf(path, sizeof(path), "/%s", p);
|
snprintf(path, sizeof(path), "/%s", stripped);
|
||||||
else
|
else
|
||||||
strlcpy(path, p, sizeof(path));
|
strlcpy(path, stripped, sizeof(path));
|
||||||
|
|
||||||
pathinfo = path;
|
|
||||||
l = strlen(scriptname);
|
l = strlen(scriptname);
|
||||||
while (l > 0 && scriptname[l - 1] == '/')
|
while (l > 0 && scriptname[l - 1] == '/')
|
||||||
l--;
|
l--;
|
||||||
if (!strncmp(scriptname, pathinfo, l))
|
if (!strncmp(scriptname, path, l) && (path[l] == '/' ||
|
||||||
pathinfo += l;
|
path[l] == '\0')) {
|
||||||
|
log_warnx("in here! %zu %s", l, path);
|
||||||
|
fcgi_send_param(c->cgibev, "PATH_INFO", &path[l]);
|
||||||
|
path[l] = '\0';
|
||||||
|
fcgi_send_param(c->cgibev, "SCRIPT_NAME", path);
|
||||||
|
} else {
|
||||||
|
fcgi_send_param(c->cgibev, "PATH_INFO", stripped);
|
||||||
|
fcgi_send_param(c->cgibev, "SCRIPT_NAME", scriptname);
|
||||||
|
}
|
||||||
|
|
||||||
log_debug("scriptname=%s ; pathinfo=%s", scriptname, pathinfo);
|
|
||||||
|
|
||||||
fcgi_begin_request(c->cgibev);
|
|
||||||
fcgi_send_param(c->cgibev, "GATEWAY_INTERFACE", "CGI/1.1");
|
fcgi_send_param(c->cgibev, "GATEWAY_INTERFACE", "CGI/1.1");
|
||||||
fcgi_send_param(c->cgibev, "GEMINI_URL_PATH", c->iri.path);
|
fcgi_send_param(c->cgibev, "GEMINI_URL_PATH", c->iri.path);
|
||||||
fcgi_send_param(c->cgibev, "QUERY_STRING", c->iri.query);
|
fcgi_send_param(c->cgibev, "QUERY_STRING", c->iri.query);
|
||||||
|
@ -415,9 +421,6 @@ fcgi_req(struct client *c, struct location *loc)
|
||||||
fcgi_send_param(c->cgibev, "SERVER_PROTOCOL", "GEMINI");
|
fcgi_send_param(c->cgibev, "SERVER_PROTOCOL", "GEMINI");
|
||||||
fcgi_send_param(c->cgibev, "SERVER_SOFTWARE", GMID_VERSION);
|
fcgi_send_param(c->cgibev, "SERVER_SOFTWARE", GMID_VERSION);
|
||||||
|
|
||||||
fcgi_send_param(c->cgibev, "SCRIPT_NAME", scriptname);
|
|
||||||
fcgi_send_param(c->cgibev, "PATH_INFO", pathinfo);
|
|
||||||
|
|
||||||
if (*c->iri.query != '\0' &&
|
if (*c->iri.query != '\0' &&
|
||||||
strchr(c->iri.query, '=') == NULL &&
|
strchr(c->iri.query, '=') == NULL &&
|
||||||
(qs = strdup(c->iri.query)) != NULL) {
|
(qs = strdup(c->iri.query)) != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue