I'm almost done with parse function, but I get 301 Moved Permanently error in the above mentioned cases. I am aware that .exe is not present in our lookup function, but shouldn't we return NULL in that case? Also, I saw that staff wrote lines to handle these two cases. In my test file, everything works, so I really have no clue what I am doing wrong.
Any idea what might the problem be, please?
Thanks!
EDIT: As always, I didn't post my code. I kind of avoid it, although I am aware that you couldn't tell anything without it. :)
Here's my parse function:
bool parse(const char* line, char* abs_path, char* query)
{
char* first_space = strchr(line, ' ');
char* second_space = strrchr(line, ' ');
int l_line = strlen(line);
int l_method = l_line - strlen(first_space);
int l_request = l_line - l_method - strlen(second_space) - 1;
char request[l_request + 1];
char method[l_method + 1];
// copy request and method into its arrays
strncpy(request, first_space + 1, l_request);
strncpy(method, line, l_method);
request[l_request] = '\0';
method[l_method] = '\0';
// check for method
if (strcmp(method, "GET") != 0)
{
error(405);
return false;
}
// check for both spaces
if (first_space == NULL || second_space == NULL)
{
error(405);
return false;
}
// make sure the beggining of the request is ok
if (request[0] != '/')
{
error(501);
return false;
}
// we dun want no quotations marks
for (int i = 0, n = strlen(request); i <= n; i++)
{
if (request[i] == '"')
{
error(400);
return false;
}
}
char* compare = strstr(line, "HTTP/1.1");
if (compare == 0)
{
error(505);
return false;
}
// makin' room for version
char* copy_version = malloc(sizeof(10));
strncpy(copy_version, compare, strlen(compare) - 2);
// query - what to do and not do if there's ? or not
char* q_mark = strchr(request, '?');
if (q_mark != NULL)
{
if (strcmp(q_mark + 1, "") == 0)
{
query = malloc(sizeof(LimitRequestLine + 1));
query[0] = '\0';
abs_path = malloc(sizeof(LimitRequestLine + 1));
strncpy(abs_path, request, strlen(request) + strlen(q_mark));
}
else if (q_mark + 1 != NULL)
{
query = malloc(sizeof(LimitRequestLine + 1));
strcpy(query, q_mark);
abs_path = malloc(sizeof(LimitRequestLine + 1));
strncpy(abs_path, request, strlen(request) - strlen(query));
}
}
else if (q_mark == NULL)
{
query = malloc(sizeof(LimitRequestLine + 1));
query[0] = '\0';
abs_path = malloc(sizeof(LimitRequestLine + 1));
strncpy(abs_path, request, strlen(request));
}
return true;
}
I would like to add that before I implemented query, I had all green smileys (except for the last one, which was "TODO"), and although I did not change a thing, later I got these three red ones. Now, when I run check50 server2, the only thing that's wrong is the last line - which means I did not implement indexes well, but I think I know how to do it properly. What bugs me, is the check50 server1.