bool parse(const char* line, char* abs_path, char* query)
{
const char* sp1 = strchr(line, ' ');
const char* sp2 = strrchr(line, ' ');
const char* slash = "/";
const char* crlf = strchr(line, '\r');
const char* method = malloc(sp1 - line)+1;
const char* req = malloc(sp2 - sp1)+1;
const char* ver = malloc(crlf - sp2)+1;
if (method == NULL)
{
return 1;
}
if (strcasecmp(method, "GET") != 0)
{
error(405);
return false;
}
if (strcmp(req, slash) != 0)
{
error(501);
return false;
}
if (strchr(req, '"') != NULL)
{
error(400);
return false;
}
if (strcasecmp(ver, "HTTP/1.1") != 0)
{
error(505);
return false;
}
if (strchr(req, '?') == NULL)
{
strcpy(abs_path, req);
return abs_path;
}
else if (strchr(req, '?') != NULL)
{
const char* qm = strchr(req, '?');
const char* quer = malloc(sp2 - qm)+1;
if (strcasecmp(quer, "") == 0)
{
query = "";
return query;
}
else if (strcasecmp(quer,"") != 0)
{
strcpy(query, quer);
return query;
}
}
error(501);
return false;
}
When I run "check50 2015.fall.pset6.server1 server.c", I get the following errors:
:) server.c exists
:) server compiles
:( HTTP/1.0 returns error code 505
\ expected output, but not "HTTP/1.1 405 Method Not Allowed\r\nCont..."
:) Method of 'abcGET' returns error code 405
:) Method of 'GETabc' returns error code 405
:( request-target without starting '/' returns error code 501
\ expected output, but not "HTTP/1.1 405 Method Not Allowed\r\nCont..."
:( request-target of abc/hello.php returns error code 501
\ expected output, but not "HTTP/1.1 405 Method Not Allowed\r\nCont..."
:( Requesting cat.exe returns error code 501
\ expected output, but not "HTTP/1.1 405 Method Not Allowed\r\nCont..."
:( Requesting non-existant file returns error code 404
\ expected output, but not "HTTP/1.1 405 Method Not Allowed\r\nCont..."
:( Requesting request-target with " returns error code 400
\ expected output, but not "HTTP/1.1 405 Method Not Allowed\r\nCont..."
:) 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
Any hints on how I am using pointers incorrectly and/or using strcmp, strchr incorrectly?