Пример #1
0
// handle a request
void requestHandle(server_request stats)
{
  
   int is_static;
   struct stat sbuf;
   char buf[MAXLINE], method[MAXLINE], uri[MAXLINE], version[MAXLINE];
   char filename[MAXLINE], cgiargs[MAXLINE];
   is_static = stats.is_static;
   sbuf = stats.sbuf;
   memcpy (buf,stats.buf,MAXLINE);
   memcpy (method, stats.method,MAXLINE);
   memcpy (uri,stats.uri,MAXLINE);
   memcpy (version, stats.version,MAXLINE);
   memcpy (filename, stats.filename,MAXLINE);
   memcpy (cgiargs, stats.cgiargs,MAXLINE);
   int fd = stats.connValue;
   //rio_t rio=stats.rio;
   /*
   rio_t rio;
   
   Rio_readinitb(&rio, fd);
   Rio_readlineb(&rio, buf, MAXLINE);
   sscanf(buf, "%s %s %s", method, uri, version);

   printf("%s %s %s\n", method, uri, version);

   if (strcasecmp(method, "GET")) {
      requestError(fd, method, "501", "Not Implemented", "CS537 Server does not implement this method");
      return;
   }
   requestReadhdrs(&rio);

   is_static = requestParseURI(uri, filename, cgiargs);
   if (stat(filename, &sbuf) < 0) {
      requestError(fd, filename, "404", "Not found", "CS537 Server could not find this file");
      return;
   }
   */

   if (is_static) {
      if (!(S_ISREG(sbuf.st_mode)) || !(S_IRUSR & sbuf.st_mode)) {
         requestError(fd, filename, "403", "Forbidden", "CS537 Server could not read this file");
         return;
      }
      requestServeStatic(fd, filename, sbuf.st_size);
   } else {
      if (!(S_ISREG(sbuf.st_mode)) || !(S_IXUSR & sbuf.st_mode)) {
         requestError(fd, filename, "403", "Forbidden", "CS537 Server could not run this CGI program");
         return;
      }
      requestServeDynamic(fd, filename, cgiargs);
   }
}
Пример #2
0
// handle a request
void requestHandle(request_t request, thread_t * thread)
{
    
    thread->Stat_thread_count++;
    if (request.is_static) {
        thread->Stat_thread_static++;
        requestServeStatic(request, request.filename, request.stat_buf.st_size, thread);
    } else {
        thread->Stat_thread_dynamic++;
        requestServeDynamic(request, request.filename, request.cgiargs, thread);
    }
}
Пример #3
0
/* handle a request */
void requestHandle(request* req)
{
	/* set the request's dispatch time */
	long t;
	t = getTime();
	req->req_dispatch = t - req->req_arrival;

	if(req->is_static)
	{
		if(!(S_ISREG(req->sbuf.st_mode))
		|| !(S_IRUSR & req->sbuf.st_mode))
		{
			requestError(	req->fd,
					req->filename,
					"403",
					"Forbidden",
					"CS537 Server could not read this file" );

			return;
		}

		requestServeStatic(	req->fd,
					req->filename,
					req->sbuf.st_size,
					req );
	}
	else
	{
		if(!(S_ISREG(req->sbuf.st_mode))
		|| !(S_IXUSR & req->sbuf.st_mode))
		{
			requestError(	req->fd,
					req->filename,
					"403",
					"Forbidden",
					"CS537 Server could not run this CGI program" );

			return;
		}

		requestServeDynamic(	req->fd,
					req->filename,
					req->cgiargs,
					req );
	}
}
Пример #4
0
// handle a request
void requestHandle(int fd, char method[MAXLINE], char uri[MAXLINE], char version[MAXLINE])
{
   int is_static;
   struct stat sbuf;
   // char buf[MAXLINE], method[MAXLINE], uri[MAXLINE], version[MAXLINE];
   char filename[MAXLINE], cgiargs[MAXLINE];
   // rio_t rio = req->rio;
   // int fd = rio->rio_fd;
   //  Rio_readinitb(&rio, fd);
   
   // printf("rio.fd: %d\n", rio->rio_fd);
  //Rio_readlineb(rio, buf, MAXLINE);
   //sscanf(buf, "%s %s %s", method, uri, version);
   //printf("readlineb\n");
  

   if (strcasecmp(method, "GET")) {
      requestError(fd, method, "501", "Not Implemented", "CS537 Server does not implement this method");
      return;
   }
   // requestReadhdrs(rio);

   is_static = requestParseURI(uri, filename, cgiargs);
   if (stat(filename, &sbuf) < 0) {
      requestError(fd, filename, "404", "Not found", "CS537 Server could not find this file");
      return;
   }

   if (is_static) {
      if (!(S_ISREG(sbuf.st_mode)) || !(S_IRUSR & sbuf.st_mode)) {
         requestError(fd, filename, "403", "Forbidden", "CS537 Server could not read this file");
         return;
      }
      requestServeStatic(fd, filename, sbuf.st_size);
   } else {
      if (!(S_ISREG(sbuf.st_mode)) || !(S_IXUSR & sbuf.st_mode)) {
         requestError(fd, filename, "403", "Forbidden", "CS537 Server could not run this CGI program");
         return;
      }
      requestServeDynamic(fd, filename, cgiargs);
   }
}
Пример #5
0
// handle a request
void requestHandle(int fd, char*buf)
{

   int is_static;
   struct stat sbuf;
   char method[MAXLINE], uri[MAXLINE], version[MAXLINE];
   char filename[MAXLINE], cgiargs[MAXLINE];

   sscanf(buf, "%s %s %s", method, uri, version);

   printf("%s %s %s\n", method, uri, version);

   if (strcasecmp(method, "GET")) {
      requestError(fd, method, "501", "Not Implemented", "CS537 Server does not implement this method");
      return;
   }

   is_static = requestParseURI(uri, filename, cgiargs);
   if (stat(filename, &sbuf) < 0) {
      requestError(fd, filename, "404", "Not found", "CS537 Server could not find this file");
      return;
   }

   if (is_static) {
      if (!(S_ISREG(sbuf.st_mode)) || !(S_IRUSR & sbuf.st_mode)) {
         requestError(fd, filename, "403", "Forbidden", "CS537 Server could not read this file");
         return;
      }
      requestServeStatic(fd, filename, sbuf.st_size);
   } else {
      if (!(S_ISREG(sbuf.st_mode)) || !(S_IXUSR & sbuf.st_mode)) {
         requestError(fd, filename, "403", "Forbidden", "CS537 Server could not run this CGI program");
         return;
      }
      requestServeDynamic(fd, filename, cgiargs);
   }
}