0

I'm trying to implement my parse function (I haven't implemented my index function yet) and am failing check50 for the checks the correspond to the parse function. I am lost on where I am going wrong.

4
  • which tests are failing? I'm tempted to say that your problems lie with parse() instead of load(). – Yuri Laguardia Nov 21 '16 at 17:05
  • Sorry, almost every test for for the server2 check. I have passed every check in the server1 check: – BlazingEskimo Nov 21 '16 at 17:07
  • server2 also tests parse(). The fact that you've passed server1 doesn't mean parse() is correct. But your load() is correct. – Yuri Laguardia Nov 21 '16 at 17:12
  • Ah, thank you for the clarification. I have edited my question to contain my parse code. – BlazingEskimo Nov 21 '16 at 17:23
1

When I insert both your load() and your parse() functions inside my server.c, the program fails only one check50.server2 test. This one (aside from the last tests, directed at indexes()):

:( Requesting hello.php? returns 200, text/html, and correct output

This last error comes from the fact that the second strtok() in the snippet below can return null when request target is only /hello.php?. You'll need to do something different than strcpy() to fill query when strtok() returns NULL bellow:

//if request target has a query attached to it, split up the query and absolute path
//copy absolute path and query to their respective values
if (strstr(request_target, "?") != NULL)
{
    char* absolute_path = strtok(request_target, "?");
    strcpy(abs_path, absolute_path);

    char* queryc = strtok(NULL, "\0");

    strcpy(query, queryc);
}

PS: These two tests are for indexes(), not parse():

:) Requesting /test/ outputs /test/index.html
:) Requesting directory containing index.php outputs index.php

EDIT to comment lookup()
Well, in the end your main problem was in lookup(). You are misunderstanding what that argument path is.

path is a long string containing the absolute path, like "/home/ubuntu/workspace/pset6/public/cat.jpg". You're comparing this long string to these small strings "jpg", "css" etc.

Will "/home/ubuntu/workspace/pset6/public/cat.jpg" ever be equal to "jpg" if you don't crop that long string first?


If this solves your problem, please come back here later and click the check mark to accept the answer so we can close the question.

7
  • That is quite odd. I just pasted what I posted here back into my server.c file but am getting the exact same errors. Could I send you my server.c file? I am currently getting these errors: sandbox.cs50.net/checks/5350c55e90fc4f7cb90e81ac9ec27529 – BlazingEskimo Nov 21 '16 at 18:05
  • Sure. Send it to me at yurilaguardia@gmail.com – Yuri Laguardia Nov 21 '16 at 18:09
  • Thank you, I have sent it off. – BlazingEskimo Nov 21 '16 at 18:19
  • Right! Got it and updated the answer. – Yuri Laguardia Nov 21 '16 at 18:30
  • 1
    Thank you, I have decided to use strchr() to fix the problem. Thanks again! – BlazingEskimo Nov 21 '16 at 20:19

You must log in to answer this question.

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