📄 htmimimp.c
字号:
/*** DEFAULT MIME HEADER PARSERS**** (c) COPYRIGHT MIT 1995.** Please first read the full copyright statement in the file COPYRIGH.** @(#) $Id: HTMIMImp.c,v 2.26 1999/02/22 22:10:11 frystyk Exp $**** This module contains the default MIME header parsers for the MIME** parser in HTMIME.c. They are all initialized at run time and can hence** be replaced or extended with your own set.**** History:** Jun 96 HFN Written** Dec 98 JKO Added support for message-digest authentication*//* Library include files */#include "wwwsys.h"#include "WWWUtil.h"#include "WWWCore.h"#include "HTHeader.h"#include "HTTPUtil.h"#include "HTMIMImp.h" /* Implemented here *//* ------------------------------------------------------------------------- */PUBLIC int HTMIME_accept (HTRequest * request, HTResponse * response, char * token, char * value){ return HT_OK;}PUBLIC int HTMIME_acceptCharset (HTRequest * request, HTResponse * response, char * token, char * value){ return HT_OK;}PUBLIC int HTMIME_acceptEncoding (HTRequest * request, HTResponse * response, char * token, char * value){ return HT_OK;}PUBLIC int HTMIME_acceptLanguage (HTRequest * request, HTResponse * response, char * token, char * value){ return HT_OK;}PUBLIC int HTMIME_acceptRanges (HTRequest * request, HTResponse * response, char * token, char * value){ if (value) { HTNet * net = HTRequest_net(request); HTHost * host = HTNet_host(net); HTHost_setRangeUnits(host, value); } return HT_OK;}PUBLIC int HTMIME_authenticate (HTRequest * request, HTResponse * response, char * token, char * value){ char * scheme = HTNextField(&value); if (scheme) { HTResponse_addChallenge(response, scheme, value); HTResponse_setScheme(response, scheme); } return HT_OK;}PUBLIC int HTMIME_authenticationInfo (HTRequest * request, HTResponse * response, char * token, char * value){ if (token && value) { HTResponse_addChallenge(response, token, value); HTResponse_setScheme(response, "digest"); } return HT_OK;}PUBLIC int HTMIME_authorization (HTRequest * request, HTResponse * response, char * token, char * value){ return HT_OK;}PUBLIC int HTMIME_cacheControl (HTRequest * request, HTResponse * response, char * token, char * value){ /* ** Walk through the set of cache-control directives and add them to the ** response association list for cache control directives */ char * name_val; while ((name_val = HTNextPair(&value)) != NULL) { char * name = HTNextField(&name_val); char * val = HTNextField(&name_val); if (name) HTResponse_addCacheControl(response, name, val ? val : ""); } return HT_OK;}PUBLIC int HTMIME_connection (HTRequest * request, HTResponse * response, char * token, char * value){ /* ** Walk through the set of connection directives and add them to the ** response association list for connection directives */ char * name_val; while ((name_val = HTNextPair(&value)) != NULL) { char * name = HTNextField(&name_val); char * val = HTNextField(&name_val); /* ** If we have a name then look if it is concerning persistent ** connections. If so, then we handle it here, otherwise we leave it ** to somebody else by simply adding it to the list of connection ** tokens. */ if (name) { HTNet * net = HTRequest_net(request); HTHost * host = HTNet_host(net); if (!strcasecomp(name, "close")) { /* HTTP/1.1 */ HTTRACE(STREAM_TRACE, "MIMEParser.. Close received...\n"); HTHost_setCloseNotification(host, YES); } else if (!strcasecomp(name, "keep-alive")) { /* HTTP/1.0 */ /* ** In case this is an HTTP/1.1 server sending keep-alive then ** ignore it. */ if (HTHost_version(host) < HTTP_11) { HTNet_setPersistent(net, YES, HT_TP_SINGLE); HTTRACE(STREAM_TRACE, "MIMEParser.. HTTP/1.0 Keep Alive\n"); } else HTTRACE(STREAM_TRACE, "MIMEParser.. HTTP/1.0 Keep Alive ignored\n"); } else HTResponse_addConnection(response, name, val ? val : ""); } } return HT_OK;}PUBLIC int HTMIME_contentEncoding (HTRequest * request, HTResponse * response, char * token, char * value){ char * field; while ((field = HTNextField(&value)) != NULL) { char * lc = field; while ((*lc = TOLOWER(*lc))) lc++; HTResponse_addEncoding(response, HTAtom_for(field)); } return HT_OK;}PUBLIC int HTMIME_contentLength (HTRequest * request, HTResponse * response, char * token, char * value){ char * field; if ((field = HTNextField(&value)) != NULL) HTResponse_setLength(response, atol(field)); return HT_OK;}PUBLIC int HTMIME_contentRange (HTRequest * request, HTResponse * response, char * token, char * value){ char * field; if ((field = HTNextField(&value))) HTResponse_addRange(response, field, value); return HT_OK;}PUBLIC int HTMIME_contentTransferEncoding (HTRequest * request, HTResponse * response, char * token, char * value){ char * field; if ((field = HTNextField(&value)) != NULL) { char *lc = field; while ((*lc = TOLOWER(*lc))) lc++; HTResponse_setContentTransferEncoding(response, HTAtom_for(field)); } return HT_OK;}PUBLIC int HTMIME_contentType (HTRequest * request, HTResponse * response, char * token, char * value){ char * field; if ((field = HTNextField(&value)) != NULL) { /* Get the Content-Type */ char *lc = field; while ((*lc = TOLOWER(*lc))) lc++; HTResponse_setFormat(response, HTAtom_for(field)); /* Get all the parameters to the Content-Type */ { char * param; while ((field = HTNextField(&value)) != NULL && (param = HTNextField(&value)) != NULL) { lc = field; while ((*lc = TOLOWER(*lc))) lc++; lc = param; while ((*lc = TOLOWER(*lc))) lc++; HTResponse_addFormatParam(response, field, param); } } } return HT_OK;}#if 0PRIVATE int HTFindInt(char * haystack, char * needle, int deflt){ char * start = strstr(haystack, needle); int value = deflt; if (start != NULL) { start += strlen(needle); while isspace(*start) start++; if (isdigit(*start)) { char * end = start + 1; char save; while (isdigit(*end)) end++; save = *end; *end = 0; value = atoi(start); *end = save; } } return value;}#endifPUBLIC int HTMIME_keepAlive (HTRequest * request, HTResponse * response, char * token, char * value){ char * name_val; HTNet * net = HTRequest_net(request); HTHost * host = HTNet_host(net); while ((name_val = HTNextPair(&value)) != NULL) { char * name = HTNextField(&name_val); char * val = HTNextField(&name_val); if (!strcasecomp(name, "max") && val) { int max = atoi(val); HTTRACE(STREAM_TRACE, "MIMEParser.. Max %d requests pr connection\n" _ max); HTHost_setReqsPerConnection(host, max); } else if (!strcasecomp(name, "timeout") && val) { int timeout = atoi(val); HTTRACE(STREAM_TRACE, "MIMEParser.. Timeout after %d secs\n" _ timeout); } } return HT_OK;}PUBLIC int HTMIME_link (HTRequest * request, HTResponse * response, char * token, char * value){ char * element; HTParentAnchor * me = HTRequest_anchor(request); while ((element = HTNextElement(&value))) { char * param_pair; char * uri = HTNextField(&element); HTChildAnchor * child_dest = HTAnchor_findChildAndLink(me, NULL, uri, NULL); HTParentAnchor * parent_dest = HTAnchor_parent(HTAnchor_followMainLink((HTAnchor *) child_dest)); if (parent_dest) { while ((param_pair = HTNextPair(&element))) { char * name = HTNextField(¶m_pair); char * val = HTNextField(¶m_pair); if (name) { if (!strcasecomp(name, "rel") && val && *val) { HTTRACE(STREAM_TRACE, "MIMEParser.. Link forward relationship `%s\'\n" _ val); HTLink_add((HTAnchor *) me, (HTAnchor *) parent_dest,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -