Example #1
0
int file_exists(char *file)
{
   char path[MAXPATHLEN], filename[MAXPATHLEN];

   strcpy(filename,file);
   if(*filename == '/'){
      strcpy(path,file);
      filehead(path);
      filetail(filename);
   }
   else
      strcpy(path, "./");
   if(find_file(path,filename))
      return(TRUE);
   else
      return(FALSE);
}
Example #2
0
int process(FILE *f)

{

  char buf[4096];

  char *method;

  char *path;

  char *protocol;

  struct stat statbuf;

  char pathbuf[4096];

  int len;


  if (!fgets(buf, sizeof(buf), f)) return -1;

  printf("Request: %s", buf);
  //splits the buf string

  method = strtok(buf, " ");

  path = strtok(NULL, " ");

  protocol = strtok(NULL, "\r");


  printf("%s", method);

  printf("%s", path);

  printf("%s", protocol);


  if (!method || !path || !protocol)
 
    return -1;


  if(strcmp(method, "GET") == 0)

    getfile(f, path, &statbuf);

  else if(strcmp(method, "HEAD") == 0)

    filehead(f, path, &statbuf);

  else if(strcmp(method, "PUT") == 0)
    putfile(f, path);

  else if(strcmp(method, "DELETE") == 0)

    removefile(f, path);


  return 0;

}