I've been working my way through PSET6, and most of it's been fine, until now. When I check the program in check50, it shows me that the first two (existing and compiling), the 5th (checking if GETabc works) and the last 3 checks (checks with spaces) work. The others, however, all get error 405, (the 4th check gets error 501). I can't seem to find out why. Can someone help me on the way? I've included my parse function, because I can tell that my mistakes are definitely there
bool parse(const char* line, char* abs_path, char* query)
{
// TODO
bool methodize = true;
bool requested = false;
bool switcher = false;
bool versioning = false;
char* method = (char *) malloc (sizeof(char) * 5);
char* httpVersion = (char *) malloc (sizeof(char) * 10);
abs_path = (char *) malloc (sizeof(char) * (LimitRequestLine + 1)) ;
int methOver = 0;
for(int i = 0; i < strlen(line); i++) {
char* s = strdup(&line[i]);
if(methodize == true) {
sprintf(method, "%s", s);
if(strncmp(s, " ", 1)) {
methodize = false;
requested = true;
methOver = i;
if(!strncmp(method, "GET ", 1)) {
error(405);
method = NULL;
return false;
}
}
} else if (requested == true) {
char* t = strdup(&line[methOver+1]);
if(strncmp(t, "/", 1)) {
error(501);
method = NULL;
return false;
}
if(strncmp(s, "\"", 1)) {
error(400);
method = NULL;
abs_path = NULL;
return false;
} else if (strncmp(s, " ", 1)) {
requested = false;
versioning = true;
} else if (!strncmp(s, "?", 1) && switcher == false){
strcpy(abs_path, &line[i]);
} else if (strncmp(s,"?", 1) && switcher == false) {
switcher = true;
} else if (switcher == true) {
sprintf(query, "%s", s);
}
} else if(versioning == true) {
if(strncmp(s, "\"", 1)) {
error(400);
abs_path = NULL;
method = NULL;
httpVersion = NULL;
return false;
} else if (i+1 == strlen(line)){
if(strncmp(httpVersion, " HTTP/1.1", strlen(httpVersion))) {
return true;
} else {
error(505);
abs_path = NULL;
method = NULL;
httpVersion = NULL;
return false;
}
} else {
sprintf(httpVersion, "%s", s);
}
}
}
error(501);
return false;
}
Thank you.