I've been working my way through the second half of PSET6, server 2, and this is what I get when I try check50:
:) server.c exists
:) server compiles
:( Requesting cat.jpg returns 200, image/jpeg, and correct image
:( Requesting cat.html returns 200, text/html, and correct file
:( Requesting cat2.HTML returns 200, text/html, and correct file
:( Requesting cat3.HtMl returns 200, text/html, and correct file
:( Requesting cat.gif returns 200, image/gif, and correct file
:( Requesting favicon.ico returns 200, image/x-icon, and correct file
:( Requesting test.css returns 200, text/css, and correct file
:( Requesting test.js returns 200, text/javascript, and correct file
:) Requesting hello.php returns 200, text/html, and correct output
:) Requesting hello.php? returns 200, text/html, and correct output
:) Requesting hello.php?name=Alice returns 200, text/html, and correct output
:) Requesting /test redirects to /test/
:( Requesting /test/ outputs /test/index.html
:( Requesting directory containing index.php outputs index.php
\ expected output, not an exit code of 0
:( Requesting two files in a row (cat.html then cat.jpg) succeeds
It's weird, because the way I check jpg, html, and the rest is the same way I check for php, and only PHP is working. Here's my lookup(), just in case I have an error there:
const char* lookup(const char* path)
{
// TODO
int len = strlen(path);
printf("%i", len);
char* s = NULL;
s = strrchr(path, '.');
printf("%s", s);
//FIND OUT WHAT'S IN S
if(strcasecmp(s, ".css") == 0) {
s = "text/css";
} else if(strcasecmp(s, ".html") == 0) {
s = "text.html";
} else if(strcasecmp(s, ".gif") == 0) {
s = "image/gif";
} else if(strcasecmp(s, ".ico") == 0) {
s = "image/x-icon";
} else if(strcasecmp(s, ".jpg") == 0) {
s = "image/jpeg";
} else if(strcasecmp(s, ".js") == 0) {
s = "text/javascript";
} else if(strcasecmp(s, ".php") == 0) {
s = "text/x-php";
} else if(strcasecmp(s, ".png") == 0) {
s = "image/png";
} else {
s = NULL;
}
return s;
}
I think, however, that the main error for the lower problems resides in indexes(), so here is that function
char* indexes(const char* path)
{
// TODO
char* check = NULL;
char* check2 = NULL;
int leng = strlen(path);
if(strncmp(&path[leng-2], "/", 1) == 0) {
sprintf(check, "%sindex.php", path);
sprintf(check2, "%sindex.html", path);
} else {
sprintf(check, "%s/index.php", path);
sprintf(check2, "%s/index.html", path);
}
printf("%s", check);
if(access(check, F_OK) == 0) {
return check;
} else if (access(check2, F_OK) == 0) {
return check2;
} else {
return NULL;
}
}
I've been reading around, looking at stuff that could help me, but I can't find anything that helps. If I could get a tip to help me on my way, that'd be great.