I only have this one problem left in check50. https://sandbox.cs50.net/checks/e3382282d5e64259adec1cc4f51b17de
I'm pretty sure the problem is in "load" (but, I could be wrong). I know it is tricky to write user input to pipe, but, if we could read bytes and store it in *content & *length, shouldn't there be a way (an easy one, I hope) to write into it? I've looked around for ideas from the forum, but it remains unclear. Here's a post where this problem was also mentioned.
I feel like I'm missing a step in load to write user input to ".php?". Can anyone please refer me to some readings where I can learn to do this? I don't think it is mentioned anywhere in materials cs50 gave us for edX students. It makes it difficult for someone like me who has NULL background of computer science to complete this pset with flying colours.
Anyway, here's my "load" codes:
Code removed per academic honesty<<
Thanks beforehand.
Edited: Now with 'parse':
bool parse(const char* line, char* abs_path, char* query)
{
// put line into tokens
char req_line[strlen(line) + 1];
strcpy(req_line, line);
char* method = strtok(req_line, " ");
char* req_tar = strtok(NULL, " ");
char* version = strtok(NULL, "\r\n\r\n");
char* absolute_path = strtok(req_tar, "?");
strcpy(abs_path, absolute_path);
for(int i = 0, n = strlen(line); i < n; i++)
{
if(strcmp(req_tar, abs_path) != 0)
query = strstr(req_tar, abs_path);
if(query[i] == '?' && strlen(query) == 1)
query[0] = '\0';
if(strcmp(method, "GET") != 0)
{
error(405);
return false;
}
if(req_tar[0] != '/')
{
error(501);
return false;
}
if(req_tar[i] == '"')
{
error(400);
return false;
}
if(line[i] == ' ' && line[i + 1] == ' ')
{
error(400);
return false;
}
if(strcmp(version, "HTTP/1.1") != 0)
{
error(505);
return false;
}
}
return true;
}
and here is the check50 server1 which shows everything is good up to some stage https://sandbox.cs50.net/checks/caad31fda59b4ca0964cd3c0710c55dc