/************************************************************************* > File Name: http.c > Author: > Mail: > Created Time: 2019年09月30日 星期一 16时32分14秒 ************************************************************************/ #include<stdio.h> #include<stdlib.h> #include<sys/socket.h> #include<sys/types.h> #include<netinet/in.h> #include<arpa/inet.h> #include<unistd.h> #include<ctype.h> #include<string.h> #include<sys/stat.h> #include<pthread.h> #include<sys/wait.h> # define SERVER_STRING "Server: jdhttpd/0.1.0 " # define ISspace(x) isspace((int)(x)) void accept_request(void *); void bad_request(int); void cat(int, FILE *); void cannot_excute(int); void error_dis(const char *); void execute_cgi(int, const char *, const char *, const char *); void headers(int, const char *); void not_found(int); void serve_file(int, const char *); void not_found(int); void serve_file(int, const char *); int startup(int *); void unimplemented(int); int get_line(int, char *, int); int pthread_create(pthread_t *thread,const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); void accept_request(void *arg){ char buf[1024]; char method[255]; char url[255]; char path[512]; int client = (intptr_t)arg; int cgi = 0; struct stat st; char *query_string = NULL; int numchars = 0; int i, j; numchars = get_line(client, buf, sizeof(buf)); i = 0, j = 0; while(!ISspace(buf[i]) && (i < sizeof(method) - 1)){ method[i] = buf[i]; i++; } j = i; method[i] = '