0

Blockquote
:) server.c exists
:) server compiles
:) HTTP/1.0 returns error code 505
:) Method of 'abcGET' returns error code 405
:) Method of 'GETabc' returns error code 405
:) request-target without starting '/' returns error code 501
:) request-target of abc/hello.php returns error code 501
:) Requesting cat.exe returns error code 501
:( Requesting non-existant file returns error code 404
\ expected output, not an exit code of 0
:) Requesting request-target with " returns error code 400
:) Two spaces after GET returns error code
:) A space within the request target returns error code
:( Two spaces before HTTP/1.1 returns error code
\ expected output, not an exit code of 0

char* abs_path, char* query) {

    // TODO

    char A[5];
    char B[LimitRequestLine + 1];
    char C[LimitRequestLine + 1];
    int i=0,j=0;
    char* p=strchr(line,' ');
    char* n=strrchr(line,' ');
    for (i=0;line[i]!=' ';i++)
    {
        A[i]=line[i];
    }
    A[i]='\0';
    if (strcmp(A,"GET")!=0)
    {
        error(405);**strong text**
        return false;
    }
    for (i=1,j=0;p[i]!=' ';i++,j++)
    {
        B[j]=p[i];
    }
    B[j]='\0';
    if (B[0]!='/')
    {
        error(501);
        return false;
    }
    for (j=0;B[j]!='\0';j++)
    {
        if (B[j]=='\"')
        {
            error(400);
            return false;
        }
    }
    for (i=1,j=0;n[i]!='\r';i++,j++)
    {
        C[j]=n[i];
    }
    C[j]='\0';
    if (strcmp(C,"HTTP/1.1")!=0)
    {
        error(505);
        return false;
    }
    const char* type=lookup(B);
    char* exist=strchr(B,'.');
    if (exist==NULL)
    {
        error(404);
    }
    else if (type==NULL)
    {
        error(501);
        return false;
    }
    strcpy(abs_path,B);
    return true;
}
4
  • :( Requesting non-existant file returns error code 404 & :( Two spaces before HTTP/1.1 returns error code Aug 21, 2016 at 18:35
  • I got these 2 errors Aug 21, 2016 at 18:36
  • please add the rest of the error message from check 50 (something like \ expected output, but not "HTTP/1.1 505 HTTP Version Not Supported...") Aug 21, 2016 at 21:24
  • I have added it Aug 22, 2016 at 12:57

1 Answer 1

1

Here are some clues.

This result from check50 \ expected output, not an exit code of 0 usually indicates a seg fault. The problem probably lies in this section:

const char* type=lookup(B);
    char* exist=strchr(B,'.');
    if (exist==NULL)
    {
        error(404);
    }
    else if (type==NULL)
    {
        error(501);
        return false;
    }

First, and foremost: don't call lookup from parse. Full stop. Read and understand the main code from around line 182. It will execute lookup when it's darn good and ready. Plus, it is not in the specification. Sometimes (almost always in this course) doing more than what's in the spec has the same penalty as doing less, whether that is a poor grade, or rejection of your code by a superior or a customer.

The reason for the seg fault is probably that you are stuffing data into type (the return value from lookup) but you have not allocated any memory for it. Since you should be removing this code, no reason to fix it, only to remember that lesson.

Now for the "two-space" problem. Let's say line is GET SP1 /cat.jpg SP2 SP3 HTTP/1.1 CRLF (using similar notation as the spec). This line char* n=strrchr(line,' '); will find SP3. Your B loop will stop processing at SP2. So "two-spaces" is not detected. Consider the fact that "two-spaces" is never allowed in a valid request-line. Perhaps you can test for that condition (think strstr) and throw an error.

And now from the broken record department. gdb is an invaluable tool for debugging server. It is worth your while to invest the time it takes to learn how to use it for this pset. You will find start tips here.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .