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

📄 config.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. */char MONKEYROOT[255]    = "smb/monkey";char SERVERCONF[255]    = "conf";char SERVER_ROOT[255]   = "htdocs";char INDEXFILE[100] 	= "htdocs/index.html";char FILE404[255] 	  = "htdocs/404.html";char FILE405[255] 	  = "htdocs/405.html";int  SERVERPORT         = 80;char INFOSERVER[255]    = "Server: Monkey\n";/* Carga en memoria los mimes registrados en mime.types */struct mimetypes {		   char name[10];	   char type[50];	   struct mimetypes *next;	 };struct mimetypes *first_mime;struct mimetypes *new_mime;struct mimetypes *aux_mime;int up_mimetypes(int argc, char** argv) {		int i;	char buffer[255];	char path[255];	char *name=0,*type=0;		FILE *mime;		/*struct stat checkdir;		strcpy(SERVERCONF,argv[1]);	stat(SERVERCONF,&checkdir);	printf ("config.h: %s\n", path);	if(!(checkdir.st_mode & S_IFDIR)){		puts("ERROR: La ruta ingresada del directorio de configuracion no es valida");		exit(0);	}*/	strcpy(path,SERVERCONF);        	strncat(path,"/mime.types",sizeof(SERVERCONF)-1);    puts(path);	if( (mime=fopen(path,"r"))==NULL ) {		puts("Error: No se puede abrir archivo mime.types");		exit(0);	}		/* Rutina que carga en memoria los mime types */	while(!feof(mime)) {		fgets(buffer,255,mime);			for(i=0; i<255 && buffer[i]!='\0'; i++)		  if(buffer[i] == '\n' || buffer[i] == '\r')	 	   buffer[i]='\0';		name  = strtok(buffer, "\"\t ");		type  = strtok(NULL, "\"\t ");		if (!name || !type) continue;		if (buffer[0] == '#') continue;		new_mime=malloc(sizeof(struct mimetypes));		strncpy(new_mime->name,name,10);		strncpy(new_mime->type,type,50);		new_mime->next=NULL;				if(first_mime==NULL)			first_mime=new_mime;		else {			aux_mime=first_mime;			while(aux_mime->next!=NULL)				aux_mime=aux_mime->next;			aux_mime->next=new_mime;		}	}	fclose(mime);	return 0;}int up_config(int argc, char** argv) {		int i;	char path[255], buffer[255];	char *variable=0, *value=0;			struct stat checkdir;		FILE *configfile;		strcpy(path,SERVERCONF);		strncat(path,"/monkey.conf",sizeof(SERVERCONF)-1);    puts(path);	if( (configfile=fopen(path,"r"))==NULL ) {		puts("Error: No se puede abrir archivo monkey.conf");		exit(0);	}		while(!feof(configfile)) {		fgets(buffer,255,configfile);	    printf("port:%s",buffer);		for(i=0; i<255 && buffer[i]!='\0'; i++)		  if(buffer[i] == '\n' || buffer[i] == '\r')	 	   buffer[i]='\0';		variable   = strtok(buffer, "\"\t ");		value	  = strtok(NULL, "\"\t ");		if (!variable || !value) continue;		if (buffer[0] == '#') continue;		if(strcmp(variable,"Monkeyroot")==0) {			strncpy(MONKEYROOT,value,255);			printf("MONKEYROOT:%s",MONKEYROOT);		}				if(strcmp(variable,"Server_root")==0) {			strncpy(SERVER_ROOT,value,255);			printf("SERVER_ROOT:%s",SERVER_ROOT);		}		if(strcmp(variable,"Port")==0) {			SERVERPORT=atoi(value);			printf("port:%d",SERVERPORT);		}		if(strcmp(variable,"Indexfile")==0) {			strcpy(INDEXFILE,"/");			strncat(INDEXFILE,value,sizeof(INDEXFILE)-1);		}	}	fclose(configfile);		/* Validando de que las variables sean rutas existentes *//*	if(stat(MONKEYROOT,&checkdir)==-1) {		puts("ERROR: La ruta ingresada para Monkeyroot en monkey.conf no es valida");		exit(0);	}	else {		if(!(checkdir.st_mode & S_IFDIR)) {			puts("ERROR: La ruta ingresada para Monkeyroot en monkey.conf no es un directorio");			exit(0);		}	}		if(stat(SERVER_ROOT,&checkdir)==-1) {		puts("ERROR: La ruta ingresada para Server_root en monkey.conf no es valida");			exit(0);	}	else {		if(!(checkdir.st_mode & S_IFDIR)) {			puts("ERROR: La ruta ingresada para Server_root en monkey.conf no es un directorio");			exit(0);			}	}		if(!SERVERPORT>=1 && !SERVERPORT<=64000) {		puts("ERROR: Numero de puerto no valido en monkey.conf");		exit(0);	}	*/	strncpy(FILE404,SERVER_ROOT,255);	strncat(FILE404,"/404.html",sizeof(FILE404)-1);	strncpy(FILE405,SERVER_ROOT,255);	strncat(FILE405,"/405.html",sizeof(FILE404)-1);	return;}

⌨️ 快捷键说明

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