⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 method.h

📁 基于linux的http服务器.代码比较简单
💻 H
字号:
/*  Monkey HTTP Daemon v0.1.1 by EdsipeR (edsiper@linux-chile.org) *  -------------------------------------------------------------- *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU Library General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Get Method */int get_method(int remote_fd, char aux_request[1024], int num_bytes, FILE *file_request) {	int size;	char filename[255],buffer[255];		char content_type[255];	char content_lenght[255];				struct stat checkdir;	struct stat sizefile;		strtok(aux_request," ");	strtok(aux_request,"?");	strncpy(filename,SERVER_ROOT,255);		filename[strlen(filename)]='\0';	if(num_bytes!=-1 && num_bytes!=0) {		if((strcmp(aux_request,"/"))==0 || aux_request[1]=='.' || aux_request[1]=='/'){			strncat(filename,INDEXFILE,sizeof(filename)-1);		}		else {			strncat(filename,aux_request,sizeof(filename)-1);				/* CheckDirectory */			stat(filename,&checkdir);			if(checkdir.st_mode & S_IFDIR) {				strncat(filename,INDEXFILE,sizeof(filename)-1);			}					}		/* Abriendo archivo */		puts(filename);		if((file_request=fopen(filename,"r"))==NULL) {			requesterror(remote_fd,file_request,404);			return; 		}			/* Buscanco MimeType */		strcpy(aux_request,filename);		find_mimetype(aux_request,content_type);		puts(content_type);		/* Calculando largo de archivo */		stat(filename,&sizefile);				size=(sizefile.st_size);		strcpy(content_lenght,"Content-Length: ");		sprintf(content_lenght,"%i\n",size);		/* Enviando respuestas */		send(remote_fd,"HTTP/1.1 200 OK\n", 16, 0); 		send(remote_fd,content_lenght,strlen(content_lenght),0);		send(remote_fd,content_type,strlen(content_type),0);				while(!feof(file_request) && file_request!=NULL){			num_bytes = fread(buffer, 1, 255, file_request);			if(send(remote_fd,buffer,num_bytes,0)==-1) break;		};		fclose(file_request);		}	return;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -