Hot answers tagged

12

I have come up with my own solution after doing some research on pointer math. I used the strchr command to find the first single space in the line (handling a 400 error if that could not be found). Then, I stored the index of the space in an int. I then called strchr() again to find a single space, passing in ptr+1 instead of line (therefore, I looked ...


6

After your content type line, try adding another \r\n to finish up.


5

When I hit my road block here, I went back to the source code and re-watched the walkthrough videos, specifically this one: https://www.youtube.com/watch?v=OnAItxJhS70 There are subtle hints throughout the video that made it all click for me. (It helped that I printed out the code to write notes on as I watched.) In particular, study how request() works. ...


5

The Stopping server message comes from the stop() function defined here: /** * Stop server, deallocating any resources. */ void stop(void) { // preserve errno across this function's library calls int errsv = errno; // announce stop printf("\033[33m"); printf("Stopping server\n"); printf("\033[39m"); // free root, which was ...


4

Don't look at it like a mountain and get so overwhelmed. It's just another pset, maybe a little more difficult than the previous ones. Start from the beginning, watch all the lectures and short videos of week 8 and try to remember as much as you can, but don't sweat it. Just start the pset and read each step carefully, it's very well described what you have ...


4

First, recall what the spec says about the request-line: Per 3.1.1 of http://tools.ietf.org/html/rfc7230, a request-line is defined as method SP request-target SP HTTP-version CRLF wherein SP represents a single space ( ) and CRLF represents \r\n. None of method, request-target, and HTTP-version, meanwhile, may contain SP. If you put some ...


4

I just completed this pset successfully.. I had the same issue and i moved on implementing the next function because if you see in the sandbox link you will find under that error written TODO..which means it will be covered in the remaining TODO functions.


4

403 Forbidden / permissions / chmod: the Definitive Guide TL;DR: PHP files and config.json need to be set to chmod 640 despite what it says in the Problem Specification. Hope this helps!


4

You would need to use debug50 or gdb to "stop the program and inspect", not check50. Since you are asking for help with debugging, my comments are intentionally cryptic. If load returns false, you will get a 500 error. Without using gdb et.al. review your function and find the place where it returns true. debug50/gdb should make it clear that load will ...


3

According to your terminal output, abs_path is wrong. Unless you have a file named hello.php?name=gege019, 404 is the right answer. abs_path should not include the ? or anything that follows.


3

On a high level I believe it is used to test whether a file exists and/or how it can be manipulated. But how exactly does it do this? According to the man pages: The check is done using the calling process's real UID and GID, rather than the effective IDs as is done when actually attempting an operation (e.g., open(2)) on the file. This allows set-user-...


3

Have you tried to kill the server process before trying those commands? killall server Also you can kill the apache process, if it's running: sudo killall apache2


2

The keyword continue simply skips the current iteration of the loop. Of course you don't wanna continue the process of responding to the client if part of this process failed. do we have to call function "write" each time we respond to client? Per the man pages of write (section 2) ssize_t write(int fd, const void *buf, size_t count); DESCRIPTION ...


2

when you look a few lines above you see how the code is responding to a php page request. Just do the same - and add a dprintf for Content-Type. // respond to client if (dprintf(cfd, "HTTP/1.1 200 OK\r\n") < 0) { continue; } if (dprintf(cfd, "Connection: close\r\n") < 0) { ...


2

This can be done by using "access", as suggested in the pset sheet. e.g. use access(path, R_OK) to check if the file is readable, and it'll return 0 if readable and return -1 if not. consult manpage for more information.


2

per the specs: Complete the implementation of support for static content in such a way that, after loading a file into memory via load, main responds to a browser with these lines HTTP/1.1 200 OK Connection: close Content-Length: %i Content-Type: %s each of which is terminated with CRLF (i.e., \r\n), which are followed after a single ...


2

method is 3 chars long and you need at least 4 characters to store the string "GET" {'G', 'E', 'T', '\0'}. so technically your variable method is not actually a string (it doesn't terminate with a '\0'). even if the first 3 characters of method and methodcmp are identical, there's no guarantee that method[3] (which is out of method's bounds) will be storing ...


2

You don't have to predeclare the length of croot and apath, and then copy the values in there. That way you spend away valuable space in memory. Also your use of the strcat() function is wrong. Here is a correct version of your program: char final[50] = {0}; char croot[] = "/home/jhavard/Dropbox/CS50/pset6/pset6/public/"; char apath[] = "thisIsThePath"; ...


2

This is a bug in clang, which has been fixed in version 3.5. The CS50 team is working on getting an update out with update50.


2

Your true proble is that you declare all your buffers as constants. See here: const char* buffestbuffer = NULL; const char* extrabuffer = NULL; const char* secondneedle = "?"; A variable declared as const cannot be changed, and so buffestbuffer and extrabuffer will always point to NULL and secondneedle will be equal to the string "?". The last one is ok if ...


2

"When all else fails, read the directions." All of this is described in the pset instructions, including how to start the server and how to test it. You just need to go through it and do what it says.


2

The staff version has this test: Ensure that path actually exists. Respond to the browser with 404 Not Found if not! before the test for the . in the absolute-path so because /cat doesn't exist in the directory, the 404 is returned. if you had a file called cat in your directory, then the . test would then fail and you'd give a 501. For example, ...


2

Needed the terminating null on reqTarget... // grab the request-target from the line printf("reqTargetStart = %d\n", reqTargetStart); printf("reqTargetEnd = %d\n", reqTargetEnd); int len = reqTargetEnd - reqTargetStart + 1; char reqTarget[len]; printf("len = %d\n", len); ...


2

Assignments are all assessed by computer. If you have uploaded to the wrong place, or uploaded the wrong pset, or even want to resubmit one, all you need to do is resubmit the new version to the appropriate assignment. Only the latest submission for each pset counts and you can resubmit until the class ends. In your case, just submit pset1 to the proper ...


2

Because you didn't initialise your first two booleans: bool validReqTargetPath; bool validReqTargetFile; when you refresh the page, it is likely that you will be given the same memory on the stack as you were given the first time through the loop... as such, the values may be bogus. Initialise those values and the segfault will be solved.


2

Well, here is the thing: I don't think you really have to allocate memory on the heap at all. Besides, you are never making use of the allocated memory and it is not recommended per the pset specification page. Let's see how you are never making use of it by looking at a relatively simpler example int i = 10; i = 20; The first statement creates an int ...


2

Per the spec respond to client (the bolds are mine): Complete the implementation of support for static content in such a way that, after loading a file into memory via load, main responds to a browser with these lines HTTP/1.1 200 OK Connection: close Content-Length: %i Content-Type: %s each of which is terminated with CRLF (i.e., \r\n), which ...


2

I'll comment it up for you. It is quite confusing at first, but you'll get your head around it :) // place the request in a char pointer called haystack const char* haystack = request; // in a pointer called needle place the memory address of CRLF (the end of the request-line) only if it exists in haystack char* needle = strstr(haystack, "\r\n"); // if ...


2

Belu, I tried this code: #include <stdio.h> #include <string.h> int main(void) { char* abs_path = "/hello.php"; char* root = "/home/jharvard/Dropbox/CS50/pset6/public"; char path[strlen(root) + strlen(abs_path) + 1]; strcpy(path, root); strcat(path, abs_path); printf("path:%s\n", path); return 0; } As follows: ...


2

Try mimicking what the distribution code used to generate the responses for the error messages and dynamic content: if (dprintf(cfd, "HTTP/1.1 200 OK\r\n") < 0) { continue; } // respond with Connection header if (dprintf(cfd, "Connection: close\r\n") < 0) { return false; } // respond with Content-Length header if (dprintf(cfd, "Content-...


Only top voted, non community-wiki answers of a minimum length are eligible