I am working on pset6 and I am having a hard time in parse function. I consistently take Error 400, so if anyone can give me a direction where my mistake is hiding it will be great! Below I have my code. Thanks in advance!
bool parse(const char* line, char* abs_path, char* query)
{
//creating pointers to the beginning of path, query and end of line
char *abspath = strstr(line, "/");
char *beg_query = strstr(line, "?");
char *lastspace = strrchr(line, ' ');
//where query ends
int end_of_query= beg_query-lastspace;
//Connecting query and absolute path to pointers
if (beg_query!=NULL)
{
strncpy(abs_path, abspath, LimitRequestLine+1);
strncpy(query, beg_query+1, LimitRequestLine+1);
}
else
{
strncpy(abs_path, abspath, LimitRequestLine+1);
query[0]='\0';
}
if (abs_path[0]!='/')
{
error(501);
return false;
}
for (int i=0; i<end_of_query; ++i)
{
if (query[i]=='"')
{
error(400);
return false;
}
}
if (strncmp(line, "GET", 3)!=0)
{
error(405);
return false;
}
//Testing if the HTTP version is HTTP/1.1
char *http_version=strstr("HTTP/1.1", line);
if (http_version==NULL)
{
error(505);
return false;
}
return true;
}