I'm almost done with server.c but can't seem to find the last error which doesn't allow me to pass check50.
I
I tried to analyse the existing responses to similar questions but couldn't use them to find my bug. Any help would be very much appreciated!
The errors I recievereceive are:
- :( Requesting cat.jpg returns 200, image/jpeg, and correct image
- :( Requesting /test/ outputs /test/index.html
- :( Requesting directory containing index.php outputs index.php
- :( Requesting two files in a row (cat.html then cat.jpg) succeeds
:( Requesting cat.jpg returns 200, image/jpeg, and correct image
:( Requesting /test/ outputs /test/index.html
:( Requesting directory containing index.php outputs index.php
:( Requesting two files in a row (cat.html then cat.jpg) succeeds
Load Function:load()
bool load(FILE* file, BYTE** content, size_t* length)
{
*content = NULL;
*length = 0;
*content = malloc(512 * sizeof(BYTE));
if (*content == NULL)
{
return false;
}
size_t size = fread(*content, sizeof(BYTE), 512, file);
while (size > 0)
{
*length += size;
*content = realloc(*content, *length * sizeof(BYTE));
if (*content == NULL)
{
return false;
}
size = fread(*content + *length, sizeof(BYTE), 512, file);
}
return true;
}
bool load(FILE* file, BYTE** content, size_t* length)
{
*content = NULL;
*length = 0;
*content = malloc(512 * sizeof(BYTE));
if (*content == NULL)
{
return false;
}
size_t size = fread(*content, sizeof(BYTE), 512, file);
while (size > 0)
{
*length += size;
*content = realloc(*content, *length * sizeof(BYTE));
if (*content == NULL)
{
return false;
}
size = fread(*content + *length, sizeof(BYTE), 512, file);
}
return true;
}
else if (strcasecmp(final, ".jpg") == 0)
{
mime = "image/jpeg";
}
else if (strcasecmp(final, ".jpg") == 0)
{
mime = "image/jpeg";
}
The error in Check50 is: \ expected an exit code of 0, not standard error of "======= Backtrace: =========\n======= M..."
except
expected an exit code of 0, not standard error of "======= Backtrace: =========\n======= M..."
except for index.php where the error is: \ expected output, not standard error of "======= Backtrace: =========\n======= M..."
expected output, not standard error of "======= Backtrace: =========\n======= M..."
char* indexes(const char* path)
{
// ensure path is readable and executable
if (access(path, R_OK | X_OK) == -1)
{
error(403);
return NULL;
}
char* path1 = malloc(60);
if (path1 == NULL)
{
return NULL;
}
strcpy(path1, path);
char* path2 = malloc(50);
if (path2 == NULL)
{
return NULL;
}
strcpy(path2, path);
strcat(path1, "index.php");
strcat(path2, "index.html");
// check if index.html or index.php exists and returns else returns NULL
if (access(path1, R_OK) != -1)
{
return path1;
}
else if (access(path2, R_OK) != -1)
{
return path2;
}
else
{
return NULL;
}
}
char* indexes(const char* path)
{
// ensure path is readable and executable
if (access(path, R_OK | X_OK) == -1)
{
error(403);
return NULL;
}
char* path1 = malloc(60);
if (path1 == NULL)
{
return NULL;
}
strcpy(path1, path);
char* path2 = malloc(50);
if (path2 == NULL)
{
return NULL;
}
strcpy(path2, path);
strcat(path1, "index.php");
strcat(path2, "index.html");
// check if index.html or index.php exists and returns else returns NULL
if (access(path1, R_OK) != -1)
{
return path1;
}
else if (access(path2, R_OK) != -1)
{
return path2;
}
else
{
return NULL;
}
}