Am really trying to solve server.c though I don't really understand the specification for load and indexes functions.
My parse and lookup seems to be working well, they passed check50 for server1 while server2 check50 failed woefully.
Please any pointer in the right direction will be greatly appreciated.
I'll also appreciate more explanation concerning what to do in load and indexes.
Here is my check50 output
~/workspace/pset6/ $ check50 2015.fall.pset6.server2 server.c
:) 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
\ expected output, not an exit code of 0
:( Requesting hello.php? returns 200, text/html, and correct output
\ expected output, not an exit code of 0
:( Requesting hello.php?name=Alice returns 200, text/html, and correct output
\ expected output, not an exit code of 0
:) Requesting /test redirects to /test/
:( Requesting /test/ outputs /test/index.html
:( Requesting directory containing index.php outputs index.php
\ expected output, but not "HTTP/1.1 200 OK\r\nContent-Type: text/h..."
:( Requesting two files in a row (cat.html then cat.jpg) succeeds
-
bool load(FILE* file, BYTE** content, size_t* length)
{
// TODO
if(file == NULL)
{
return false;
}
*content = NULL;
*length = 0;
BYTE* buf = (BYTE*)malloc(BYTES * sizeof(BYTE));
int counter =0;
while(fread(buf, BYTES, 1, file) != 0)
{
length++;
counter++;
if(counter == 1)
{
content = &buf;
}
buf = (BYTE*)realloc(buf, BYTES * sizeof(BYTE));
if(buf == NULL)
{
return false;
}
}
return true;
}
-
char* indexes(const char* path)
{
// TODO
size_t len = strlen(path);
char* new_path= malloc(len * sizeof(char));
strcpy(new_path, path);
char* new_pathp = malloc((len +10) * sizeof(char));
char* new_pathh = malloc((len + 11) * sizeof(char));
char* index1 = "index.php";
char* index2 = "index.html";
new_pathp = strcat(new_path, index1);
new_pathh = strcat(new_path, index2);
if(access(new_pathp, F_OK) != -1)
{
free(new_path);
return new_pathp;
}
else if(access(new_pathh, F_OK) != -1)
{
free(new_path);
return new_pathh;
}
else
return NULL;
}