I am having trouble addressing the below two errors when I run the first check50 of pset6.
check50 2015.fall.pset6.server1 server.c
:( Requesting cat.exe returns error code 501
\ expected output, but not "HTTP/1.1 505 HTTP Version Not Supported..."
:( Requesting non-existant file returns error code 404
\ expected output, but not "HTTP/1.1 505 HTTP Version Not Supported..."
I have been stuck on this for quite a while. Any thoughts or suggestions would be immensely appreciated!
bool parse(const char* line, char* abs_path, char* query)
{
int length = strlen(line);
int spaceLocation = 0;
int quesLocation = 0;
int endLocation = 0;
// check method GET
if (line[0] != 'G' || line[1] != 'E' || line[2] != 'T' || line[3] != ' ')
{
error(405);
return false;
}
// find second space and \r\n
for (int i = 4; i < length; i++)
{
if (line[i] == ' ')
{
spaceLocation = i;
}
if (line[i] == '\'')
{
endLocation = i;
}
}
// check request-target
if (line[4] != '/')
{
error(501);
return false;
}
if (strchr(line, '"') != NULL)
{
error(400);
return false;
}
// find query (if any)
int count = 0;
for (int i = 4; i < spaceLocation; i++)
{
if (line[i] == '?')
{
quesLocation = i;
count++;
}
}
if (count > 1)
{
error(400);
return false;
}
else if (count == 1)
{
for (int i = quesLocation + 1; i < spaceLocation; i++)
{
if (line[i] == '"')
{
error(400);
return false;
}
}
int queryLen = spaceLocation - quesLocation - 1;
char queryTemp[queryLen];
for (int j = 0; j < queryLen; j++)
{
queryTemp[j] = line[quesLocation + 1 + j];
}
query = queryTemp;
}
int pathLen = quesLocation - 3 - 1;
char pathTemp[pathLen];
for (int j = 0; j < pathLen; j++)
{
pathTemp[j] = line[4 + j];
}
abs_path = pathTemp;
// check HTTP-version
char httpVersion [8];
httpVersion [0] = 'H';
httpVersion [1] = 'T';
httpVersion [2] = 'T';
httpVersion [3] = 'P';
httpVersion [4] = '/';
httpVersion [5] = '1';
httpVersion [6] = '.';
httpVersion [7] = '1';
if ((endLocation - (spaceLocation + 1)) != 8)
{
error(505);
return false;
}
else
{
for (int i = 0; i < 8; i++)
{
if (line[spaceLocation + 1 + i] != httpVersion[i])
{
error(505);
return false;
}
}
}
error(501);
return false;
}