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

📄 api.c.svn-base

📁 The Wifidog project is an open source captive portal solution. It was designed primarily for wireles
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
						HTTP_MAX_URL);				}			}#endif			/* acv@acv.ca/wifidog: Added decoding of host: if			 * present. */			if (strncasecmp(buf,"Host: ",6) == 0)			{				cp = index(buf,':') + 2;				if(cp)				{					strncpy(r->request.host,cp,						HTTP_MAX_URL);				}			}			/* End modification */#if 0			if (strncasecmp(buf,"If-Modified-Since: ",19) == 0)			{				cp = index(buf,':') + 2;				if(cp)				{					strncpy(r->request.ifModified,cp,						HTTP_MAX_URL);					cp = index(r->request.ifModified,						';');					if (cp)						*cp = 0;				}			}			if (strncasecmp(buf,"Content-Type: ",14) == 0)			{				cp = index(buf,':') + 2;				if(cp)				{					strncpy(r->request.contentType,cp,						HTTP_MAX_URL);				}			}			if (strncasecmp(buf,"Content-Length: ",16) == 0)			{				cp = index(buf,':') + 2;				if(cp)					r->request.contentLength=atoi(cp);			}#endif			continue;		}	}#if 0	/* XXX: For WifiDog, we only process the query string parameters	   but keep the GET variables in the request.query!	*/	/*	** Process and POST data	*/	if (r->request.contentLength > 0)	{		bzero(buf, HTTP_MAX_LEN);		_httpd_readBuf(r, buf, r->request.contentLength);		_httpd_storeData(r, buf);			}#endif	/*	** Process any URL data	*/	cp = index(r->request.path,'?');	if (cp != NULL)	{		*cp++ = 0;		strncpy(r->request.query, cp, sizeof(r->request.query));		_httpd_storeData(r, cp);	}	return(0);}void httpdEndRequest(request *r){	_httpd_freeVariables(r->variables);	shutdown(r->clientSock,2);	close(r->clientSock);	free(r);}void httpdFreeVariables(request *r){        _httpd_freeVariables(r->variables);}void httpdDumpVariables(request *r){	httpVar	*curVar,		*curVal;	curVar = r->variables;	while(curVar)	{		printf("Variable '%s'\n", curVar->name);		curVal = curVar;		while(curVal)		{			printf("\t= '%s'\n",curVal->value);			curVal = curVal->nextValue;		}		curVar = curVar->nextVariable;	}}void httpdSetFileBase(server, path)	httpd	*server;	char	*path;{	strncpy(server->fileBasePath, path, HTTP_MAX_URL);}int httpdAddFileContent(server, dir, name, indexFlag, preload, path)	httpd	*server;	char	*dir,		*name;	int	(*preload)();	int	indexFlag;	char	*path;{	httpDir	*dirPtr;	httpContent *newEntry;	dirPtr = _httpd_findContentDir(server, dir, HTTP_TRUE);	newEntry =  malloc(sizeof(httpContent));	if (newEntry == NULL)		return(-1);	bzero(newEntry,sizeof(httpContent));	newEntry->name = strdup(name);	newEntry->type = HTTP_FILE;	newEntry->indexFlag = indexFlag;	newEntry->preload = preload;	newEntry->next = dirPtr->entries;	dirPtr->entries = newEntry;	if (*path == '/')	{		/* Absolute path */		newEntry->path = strdup(path);	}	else	{		/* Path relative to base path */		newEntry->path = malloc(strlen(server->fileBasePath) +			strlen(path) + 2);		snprintf(newEntry->path, HTTP_MAX_URL, "%s/%s",			server->fileBasePath, path);	}	return(0);}int httpdAddWildcardContent(server, dir, preload, path)	httpd	*server;	char	*dir;	int	(*preload)();	char	*path;{	httpDir	*dirPtr;	httpContent *newEntry;	dirPtr = _httpd_findContentDir(server, dir, HTTP_TRUE);	newEntry =  malloc(sizeof(httpContent));	if (newEntry == NULL)		return(-1);	bzero(newEntry,sizeof(httpContent));	newEntry->name = NULL;	newEntry->type = HTTP_WILDCARD;	newEntry->indexFlag = HTTP_FALSE;	newEntry->preload = preload;	newEntry->next = dirPtr->entries;	dirPtr->entries = newEntry;	if (*path == '/')	{		/* Absolute path */		newEntry->path = strdup(path);	}	else	{		/* Path relative to base path */		newEntry->path = malloc(strlen(server->fileBasePath) +			strlen(path) + 2);		snprintf(newEntry->path, HTTP_MAX_URL, "%s/%s",			server->fileBasePath, path);	}	return(0);}int httpdAddC404Content(server, function)	httpd	*server;	void	(*function)();{	if (!server->handle404) {		server->handle404 = (http404*)malloc(sizeof(http404));	}	if (!server->handle404) {		return(-1);	}	server->handle404->function = function;	return(0);}int httpdAddCContent(server, dir, name, indexFlag, preload, function)	httpd	*server;	char	*dir;	char	*name;	int	(*preload)();	void	(*function)();{	httpDir	*dirPtr;	httpContent *newEntry;		dirPtr = _httpd_findContentDir(server, dir, HTTP_TRUE);	newEntry =  malloc(sizeof(httpContent));	if (newEntry == NULL)		return(-1);	bzero(newEntry,sizeof(httpContent));	newEntry->name = strdup(name);	newEntry->type = HTTP_C_FUNCT;	newEntry->indexFlag = indexFlag;	newEntry->function = function;	newEntry->preload = preload;	newEntry->next = dirPtr->entries;	dirPtr->entries = newEntry;	return(0);}int httpdAddCWildcardContent(server, dir, preload, function)	httpd	*server;	char	*dir;	int	(*preload)();	void	(*function)();{	httpDir	*dirPtr;	httpContent *newEntry;	dirPtr = _httpd_findContentDir(server, dir, HTTP_TRUE);	newEntry =  malloc(sizeof(httpContent));	if (newEntry == NULL)		return(-1);	bzero(newEntry,sizeof(httpContent));	newEntry->name = NULL;	newEntry->type = HTTP_C_WILDCARD;	newEntry->indexFlag = HTTP_FALSE;	newEntry->function = function;	newEntry->preload = preload;	newEntry->next = dirPtr->entries;	dirPtr->entries = newEntry;	return(0);}int httpdAddStaticContent(server, dir, name, indexFlag, preload, data)	httpd	*server;	char	*dir;	char	*name;	int	(*preload)();	char	*data;{	httpDir	*dirPtr;	httpContent *newEntry;	dirPtr = _httpd_findContentDir(server, dir, HTTP_TRUE);	newEntry =  malloc(sizeof(httpContent));	if (newEntry == NULL)		return(-1);	bzero(newEntry,sizeof(httpContent));	newEntry->name = strdup(name);	newEntry->type = HTTP_STATIC;	newEntry->indexFlag = indexFlag;	newEntry->data = data;	newEntry->preload = preload;	newEntry->next = dirPtr->entries;	dirPtr->entries = newEntry;	return(0);}void httpdSendHeaders(request *r){	_httpd_sendHeaders(r, 0, 0);}void httpdSetResponse(request *r, char *msg){	strncpy(r->response.response, msg, HTTP_MAX_URL);}void httpdSetContentType(request *r, char *type){	strcpy(r->response.contentType, type);}void httpdAddHeader(request *r, char *msg){	strcat(r->response.headers,msg);	if (msg[strlen(msg) - 1] != '\n')		strcat(r->response.headers,"\n");}void httpdSetCookie(request *r, char *name, char *value){	char	buf[HTTP_MAX_URL];	snprintf(buf,HTTP_MAX_URL, "Set-Cookie: %s=%s; path=/;", name, value);	httpdAddHeader(r, buf);}void httpdOutput(request *r, char *msg){	char	buf[HTTP_MAX_LEN],		varName[80],		*src,		*dest;	int	count;	src = msg;	dest = buf;	count = 0;	while(*src && count < HTTP_MAX_LEN)	{		if (*src == '$')		{			char	*cp,				*tmp;			int	count2;			httpVar	*curVar;			tmp = src + 1;			cp = varName;			count2 = 0;			while(*tmp&&(isalnum(*tmp)||*tmp == '_')&&count2 < 80)			{				*cp++ = *tmp++;				count2++;			}			*cp = 0;			curVar = httpdGetVariableByName(r,varName);			if (curVar)			{				strcpy(dest, curVar->value);				dest = dest + strlen(dest);				count += strlen(dest);			}			else			{				*dest++ = '$';				strcpy(dest, varName);				dest += strlen(varName);				count += 1 + strlen(varName);			}			src = src + strlen(varName) + 1;			continue;		}		*dest++ = *src++;		count++;	}		*dest = 0;	r->response.responseLength += strlen(buf);	if (r->response.headersSent == 0)		httpdSendHeaders(r);	_httpd_net_write( r->clientSock, buf, strlen(buf));}#ifdef HAVE_STDARG_Hvoid httpdPrintf(request *r, char *fmt, ...){#elsevoid httpdPrintf(va_alist)        va_dcl{        request		*r;;        char		*fmt;#endif        va_list         args;	char		buf[HTTP_MAX_LEN];#ifdef HAVE_STDARG_H        va_start(args, fmt);#else        va_start(args);        r = (request *) va_arg(args, request * );        fmt = (char *) va_arg(args, char *);#endif	if (r->response.headersSent == 0)		httpdSendHeaders(r);	vsnprintf(buf, HTTP_MAX_LEN, fmt, args);	r->response.responseLength += strlen(buf);	_httpd_net_write( r->clientSock, buf, strlen(buf));}void httpdProcessRequest(httpd *server, request *r){	char	dirName[HTTP_MAX_URL],		entryName[HTTP_MAX_URL],		*cp;	httpDir	*dir;	httpContent *entry;	r->response.responseLength = 0;	strncpy(dirName, httpdRequestPath(r), HTTP_MAX_URL);	cp = rindex(dirName, '/');	if (cp == NULL)	{		printf("Invalid request path '%s'\n",dirName);		return;	}	strncpy(entryName, cp + 1, HTTP_MAX_URL);	if (cp != dirName)		*cp = 0;	else		*(cp+1) = 0;	dir = _httpd_findContentDir(server, dirName, HTTP_FALSE);	if (dir == NULL)	{		_httpd_send404(server, r);		_httpd_writeAccessLog(server, r);		return;	}	entry = _httpd_findContentEntry(r, dir, entryName);	if (entry == NULL)	{		_httpd_send404(server, r);		_httpd_writeAccessLog(server, r);		return;	}	if (entry->preload)	{		if ((entry->preload)(server) < 0)		{			_httpd_writeAccessLog(server, r);			return;		}	}	switch(entry->type)	{		case HTTP_C_FUNCT:		case HTTP_C_WILDCARD:			(entry->function)(server, r);			break;		case HTTP_STATIC:			_httpd_sendStatic(server, r, entry->data);			break;		case HTTP_FILE:			_httpd_sendFile(server, r, entry->path);			break;		case HTTP_WILDCARD:			if (_httpd_sendDirectoryEntry(server, r, entry,						entryName)<0)			{				_httpd_send404(server, r);			}			break;	}	_httpd_writeAccessLog(server, r);}void httpdSetAccessLog(server, fp)	httpd	*server;	FILE	*fp;{	server->accessLog = fp;}void httpdSetErrorLog(server, fp)	httpd	*server;	FILE	*fp;{	server->errorLog = fp;}void httpdAuthenticate(request *r, char *realm){	char	buffer[255];	if (r->request.authLength == 0)	{		httpdSetResponse(r, "401 Please Authenticate");		snprintf(buffer,sizeof(buffer), 			"WWW-Authenticate: Basic realm=\"%s\"\n", realm);		httpdAddHeader(r, buffer);		httpdOutput(r,"\n");	}}void httpdForceAuthenticate(request *r, char *realm){	char	buffer[255];	httpdSetResponse(r, "401 Please Authenticate");	snprintf(buffer,sizeof(buffer), 		"WWW-Authenticate: Basic realm=\"%s\"\n", realm);	httpdAddHeader(r, buffer);	httpdOutput(r,"\n");}

⌨️ 快捷键说明

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