I'm working on parse for pset6 and for some reason I can't correctly check the HTTP version. Check50 gives me "\ expected output, not an exit code of 0" which I understand stands for segmentation fault. My code:
bool parse(const char* line, char* abs_path, char* query)
{
//check for more than 2 spaces in line
int spaces = 0;
for (int i = 0, lenght = strlen(line); i < lenght; i++)
{
if (line[i] == ' ')
spaces++;
if (spaces > 2)
{
error(400);
return false;
}
}
//check for method
if (strncmp (line, "GET ", 4) != 0)
{
error(405);
return false;
}
//check for '/' at the start request target
char* SP = strchr(line, ' ');
if (SP[1] != '/')
{
error(501);
return false;
}
//check for " in the request target
//otherwise copy to abs_path
int iter = 1;
while (SP[iter] != ' ' || SP[iter] != '?')
{
if (SP[iter] == '"')
{
error(400);
return false;
}
strncpy(&abs_path[iter - 1], &SP[iter], 1);
iter++;
}
//if query exists, copy to query
if (SP[iter] == '?' && SP[iter+1] == '=')
{
int query_iter = 0;
while (SP[iter] != ' ')
{
strncpy(&query[query_iter], &SP[iter], 1);
iter++;
query_iter++;
}
}
//check for http version
SP = strrchr(line, ' ');
if (strncmp(SP, "HTTP/1.1", 8) != 0)
{
error(505);
return false;
}
error(501);
return false;
}
From check50:
:) server.c exists
:) server compiles
:( HTTP/1.0 returns error code 505
\ expected output, not an exit code of 0
:) Method of 'abcGET' returns error code 405
:) Method of 'GETabc' returns error code 405
:) request-target without starting '/' returns error code 501
:) request-target of abc/hello.php returns error code 501
:( Requesting cat.exe returns error code 501
\ expected output, not an exit code of 0
:( Requesting non-existant file returns error code 404
\ expected output, not an exit code of 0
:) Requesting request-target with " returns error code 400
:) Two spaces after GET returns error code
:) A space within the request target returns error code
:) Two spaces before HTTP/1.1 returns error code
I know there are two more errors, yet I chose to adress the HTTP first. Any help will be appreciated.