Here is my code for the parse function for PSET6. I am not sure why I get the 501 fail. (I'm not told to do the one for 404).
bool parse(const char* line, char* abs_path, char* query)
{
char* buffer = malloc(sizeof(line));
strcpy( buffer, line);
char* firstsp = strtok( buffer, " ");
char* scndsp = strtok( NULL, " ");
char* thirdsp = strtok( NULL, " ");
char* ver = strtok( thirdsp, "\\");
char method[ strlen(firstsp) + 1 ];
char request[ strlen(scndsp) + 1 ];
char http[ strlen(ver) + 1 ];
strcpy( method, firstsp);
strcpy( request, scndsp);
strcpy( http, ver);
if ( strcmp(method, "GET") != 0 )
{
error(405);
return false;
}
if ( request[0] != '/')
{
error(501);
return false;
}
if ( strchr( request, '\"') != NULL )
{
error(400);
return false;
}
if (strcmp( http, "HTTP/1.1") != 0)
{
error(505);
return false;
}
abs_path = request;
int b;
for ( b = 0; b < strlen(scndsp); b++ )
{
if ( scndsp[b] == '?' )
{
break;
}
}
if ( strchr( scndsp, '=') != NULL)
{
while (scndsp[b] != ' ' )
{
query[b] = scndsp[b];
b++;
}
}
else
{
query[0] = '\0';
}
return true;
}
Check50:
:) server.c exists
:) server compiles
:) HTTP/1.0 returns error code 505
:) 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, 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..."
:) 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
Thanks a lot,