I've been slowly working through this problem set for a couple weeks now, and I think I've hit a brick wall. Giving just a general overview, I believe at this point that I have successfully completed: validating request-line, extract query from request-target, concatenate root and absolute-path, ensure path exists, ensure path is readable, and extract path's extension. Now I have to complete "respond to client", and there doesn't seem to be much direction given on how to tackle this one. The only reference I have is the "dynamic content" part of the code in server.c. I actually used that part of the code for the "respond to client" for static content to see if it worked (while adding one statement for "type"), and it didn't. I am getting a seg fault as well when I submit a get request for static content, which leads me to believe that it is the "respond to client" problem I have to resolve, and not the previous code that I have completed (hopefully).
In addition, when I ran valgrind on my program I got 2 leaks which I don't even think are my fault. The leaks are the following:
HEAP SUMMARY:
==13895== in use at exit: 4,123 bytes in 2 blocks
==13895== total heap usage: 4 allocs, 2 frees, 4,177 bytes allocated
==13895==
==13895== Searching for pointers to 2 not-freed blocks
==13895== Checked 61,900 bytes
==13895==
==13895== 27 bytes in 1 blocks are still reachable in loss record 1 of 2
==13895== at 0x402C324: realloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==13895== by 0x804A671: parse (server.c:723)
==13895== by 0x8048F99: main (server.c:122)
==13895==
==13895== 4,096 bytes in 1 blocks are still reachable in loss record 2 of 2
==13895== at 0x402A17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==13895== by 0x40CC73F: realpath@@GLIBC_2.3 (canonicalize.c:78)
==13895== by 0x8049F96: start (server.c:783)
==13895== by 0x8048F4D: main (server.c:107)
Also valgrind tells me that I have 1 error. It's giving me an "invalid write of size 1" error, and it is related to the strcpy function when it is being used to copy from "extension" to "new_extension". I checked my implementation of "extension" to see if it was the proper size, and it is. It is 4 for html, 3 for php etc. The error is the following:
ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==13895==
==13895== 1 errors in context 1 of 1:
==13895== Invalid write of size 1
==13895== at 0x402D4EE: strcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==13895== by 0x804AD34: lookup (server.c:634)
==13895== by 0x8049CD0: main (server.c:390)
==13895== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==13895==
==13895== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Lastly, to wrap it all up, when I test my program out on telnet, it seems to work for any dynamic(php) get request, because I get an OK back and it doesn't seg fault. However, when I test my program out on telnet by submitting a get request for static(html) content it seg faults. This leads me to believe that it's because I am not done correctly finishing "respond to client", although it may be because of something else I did. When I tried testing my program out with google chrome, it seg faults on both static and dynamic get requests. It seems to seg fault on dynamic requests, because it seg faults right after it tries to get "favicon".
Any thoughts from anyone on all of this? I will be more than happy to PM my code if someone is willing to help me out, maybe I am doing something completely wrong that someone can point out. This problem set is driving me nuts, and I just want to finally finish it up!