Error handling pidt waitint status pidt pid if pid

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ], uri[MAXLINE], version[MAXLINE]; char filename[MAXLINE], cgiargs[MAXLINE]; /* read request line and headers */ Readline(fd, buf, MAXLINE); sscanf(buf, "%s %s %s\n", method, uri, version); if (strcasecmp(method, "GET")) { clienterror(fd, method, "501", "Not Implemented", "Tiny does not implement this method"); return; } read_requesthdrs(fd); /* parse URI from GET request */ is_static = parse_uri(uri, filename, cgiargs); if (stat(filename, &sbuf) < 0) { clienterror(fd, filename, "404", "Not found", "Tiny couldn’t find this file"); return; } if (is_static) { /* serve static content */ if (!(S_ISREG(sbuf.st_mode)) || !(S_IRUSR & sbuf.st_mode)) { clienterror(fd, filename, "403", "Forbidden", "Tiny couldn’t read the file"); return; } serve_static(fd, filename, sbuf.st_size); } else { /* serve dynamic content */ if (!(S_ISREG(sbuf.st_mode)) || !(S_IXUSR & sbuf.st_mode)) { clienterror(fd, filename, "403", "Forbidden", "Tiny couldn’t run the CGI program"); return; } serve_dynamic(fd, filename, cgiargs); } } code/net/tiny/tiny.c Figure 12.47: T INY doit: Handles one HTTP transaction. 12.8. PUTTING IT TOGETHER: THE TINY WEB SERVER 657 The clienterror Function T INY lacks many of the robustness features of a real server. However it does check for some obvious errors and reports them to the client. The clienterror function i...
View Full Document

Ask a homework question - tutors are online