1

I am currently writing the parse method for pset6 server.c. I have rewritten it many times and I have never gotten it to work. I currently am getting 403 forbidden every time I try to run it. Here is my code:

const char* temp = line;
char method[3];
int place = 0;
char* crawler = strstr(temp, " ");
place = crawler - temp;
strncpy(method, temp, place);
method[place] = 0;
if (strcmp(method, "GET") != 0) {
    error(405);
    return false;
}
crawler = crawler+1;
place = strstr(crawler, " ") - crawler;
char target[place];
strncpy(target, crawler, place);
target[place] = 0;
if (strstr(target, "/") != 0) {
    error(400);
    return false;
}
crawler = crawler + 2;;
if (strcmp(crawler, "HTTP/1.1\r\n") != 0) {
    error(505);
    return false;
}
if (strstr(target, "?") != NULL) {
    crawler = strstr(target, "?");
    place = crawler - target;
    strncpy(abs_path, target, place);
    strcpy(query, crawler+1);
}else if (strstr(target, "q=") != NULL) {
    crawler = strstr(target, "q=");
    place = crawler - target;
    strncpy(abs_path, target, place);
    strcpy(query, crawler);
}else{
    strcpy(abs_path, target);
    query = "";
}
return true;

Any suggestions?

You must log in to answer this question.

Browse other questions tagged .