Annotation of libwww/Library/src/HTMIMImp.c, revision 2.10
2.1 frystyk 1: /*
2.8 frystyk 2: ** DEFAULT MIME HEADER PARSERS
2.1 frystyk 3: **
4: ** (c) COPYRIGHT MIT 1995.
5: ** Please first read the full copyright statement in the file COPYRIGH.
2.10 ! frystyk 6: ** @(#) $Id: HTMIMImp.c,v 2.9 1996/11/30 23:31:37 frystyk Exp $
2.1 frystyk 7: **
8: ** This module contains the default MIME header parsers for the MIME
9: ** parser in HTMIME.c. They are all initialized at run time and can hence
10: ** be replaced or extended with your own set.
11: **
12: ** History:
13: ** Jun 96 HFN Written
14: */
15:
16: /* Library include files */
17: #include "sysdep.h"
18: #include "WWWUtil.h"
19: #include "WWWCore.h"
20: #include "HTHeader.h"
2.10 ! frystyk 21: #include "HTTPUtil.h"
2.1 frystyk 22: #include "HTMIMImp.h" /* Implemented here */
23:
24: /* ------------------------------------------------------------------------- */
25:
2.8 frystyk 26: PUBLIC int HTMIME_accept (HTRequest * request, HTResponse * response,
27: char * token, char * value)
2.1 frystyk 28: {
29:
30: return HT_OK;
31: }
32:
2.8 frystyk 33: PUBLIC int HTMIME_acceptCharset (HTRequest * request, HTResponse * response,
34: char * token, char * value)
2.1 frystyk 35: {
36:
37: return HT_OK;
38: }
39:
2.8 frystyk 40: PUBLIC int HTMIME_acceptEncoding (HTRequest * request, HTResponse * response,
41: char * token, char * value)
2.1 frystyk 42: {
43:
44: return HT_OK;
45: }
46:
2.8 frystyk 47: PUBLIC int HTMIME_acceptLanguage (HTRequest * request, HTResponse * response,
48: char * token, char * value)
2.1 frystyk 49: {
50:
51: return HT_OK;
52: }
53:
2.8 frystyk 54: PUBLIC int HTMIME_acceptRanges (HTRequest * request, HTResponse * response,
55: char * token, char * value)
2.1 frystyk 56: {
2.8 frystyk 57: if (value) {
58: HTNet * net = HTRequest_net(request);
59: HTHost * host = HTNet_host(net);
60: HTHost_setRangeUnits(host, value);
2.1 frystyk 61: }
62: return HT_OK;
63: }
64:
2.8 frystyk 65: PUBLIC int HTMIME_authenticate (HTRequest * request, HTResponse * response,
66: char * token, char * value)
2.3 frystyk 67: {
68: char * scheme = HTNextField(&value);
2.4 frystyk 69: if (scheme) {
2.8 frystyk 70: HTResponse_addChallenge(response, scheme, value);
71: HTResponse_setScheme(response, scheme);
2.4 frystyk 72: }
2.3 frystyk 73: return HT_OK;
74: }
75:
2.8 frystyk 76: PUBLIC int HTMIME_authorization (HTRequest * request, HTResponse * response,
77: char * token, char * value)
2.1 frystyk 78: {
79:
80: return HT_OK;
81: }
82:
2.8 frystyk 83: PUBLIC int HTMIME_cacheControl (HTRequest * request, HTResponse * response,
84: char * token, char * value)
2.1 frystyk 85: {
2.7 frystyk 86: /*
87: ** Walk through the set of cache-control directives and add them to the
88: ** response association list for cache control directives
89: */
90: char * name_val;
91: while ((name_val = HTNextPair(&value)) != NULL) {
92: char * name = HTNextField(&name_val);
93: char * val = HTNextField(&name_val);
2.8 frystyk 94: if (name) HTResponse_addCacheControl(response, name, val ? val : "");
2.7 frystyk 95: }
2.1 frystyk 96: return HT_OK;
97: }
98:
2.8 frystyk 99: PUBLIC int HTMIME_connection (HTRequest * request, HTResponse * response,
100: char * token, char * value)
2.1 frystyk 101: {
2.7 frystyk 102: /*
103: ** Walk through the set of connection directives and add them to the
104: ** response association list for connection directives
105: */
106: char * name_val;
107: while ((name_val = HTNextPair(&value)) != NULL) {
108: char * name = HTNextField(&name_val);
109: char * val = HTNextField(&name_val);
110:
111: /*
112: ** If we have a name then look if it is concerning persistent
113: ** connections. If so, then we handle it here, otherwise we leave it
114: ** to somebody else by simply adding it to the list of connection
115: ** tokens.
116: */
117: if (name) {
118: if (!strcasecomp(name, "close")) { /* HTTP/1.1 */
119: HTNet * net = HTRequest_net(request);
2.9 frystyk 120: #ifndef HT_MUX
2.7 frystyk 121: HTNet_setPersistent(net, NO, HT_TP_INTERLEAVE);
2.9 frystyk 122: #else
123: HTNet_setPersistent(net, NO, HT_TP_PIPELINE);
124: #endif
2.7 frystyk 125: if (STREAM_TRACE) HTTrace("MIMEParser.. Close negotiated\n");
126: } else if (!strcasecomp(name, "keep-alive")) { /* HTTP/1.0 */
127: HTNet * net = HTRequest_net(request);
2.10 ! frystyk 128: HTHost * host = HTNet_host(net);
! 129:
! 130: /*
! 131: ** In case this is an HTTP/1.1 server sending keep-alive then
! 132: ** ignore it.
! 133: */
! 134: if (HTHost_version(host) < HTTP_11) {
! 135: HTNet_setPersistent(net, YES, HT_TP_SINGLE);
! 136: if (STREAM_TRACE) HTTrace("MIMEParser.. HTTP/1.0 Keep Alive\n");
! 137: } else
! 138: if (STREAM_TRACE) HTTrace("MIMEParser.. HTTP/1.0 Keep Alive ignored\n");
2.7 frystyk 139: } else
2.8 frystyk 140: HTResponse_addConnection(response, name, val ? val : "");
2.1 frystyk 141: }
142: }
143: return HT_OK;
144: }
145:
2.8 frystyk 146: PUBLIC int HTMIME_contentEncoding (HTRequest * request, HTResponse * response,
147: char * token, char * value)
2.1 frystyk 148: {
149: char * field;
150: while ((field = HTNextField(&value)) != NULL) {
151: char * lc = field;
152: while ((*lc = TOLOWER(*lc))) lc++;
2.8 frystyk 153: HTResponse_addEncoding(response, HTAtom_for(field));
2.1 frystyk 154: }
155: return HT_OK;
156: }
157:
2.8 frystyk 158: PUBLIC int HTMIME_contentLength (HTRequest * request, HTResponse * response,
159: char * token, char * value)
2.1 frystyk 160: {
161: char * field;
162: if ((field = HTNextField(&value)) != NULL)
2.8 frystyk 163: HTResponse_setLength(response, atol(field));
2.1 frystyk 164: return HT_OK;
165: }
166:
2.8 frystyk 167: PUBLIC int HTMIME_contentRange (HTRequest * request, HTResponse * response,
168: char * token, char * value)
2.1 frystyk 169: {
2.2 frystyk 170: char * field;
2.8 frystyk 171: if ((field = HTNextField(&value)))
172: HTResponse_addRange(response, field, value);
2.1 frystyk 173: return HT_OK;
174: }
175:
2.8 frystyk 176: PUBLIC int HTMIME_contentTransferEncoding (HTRequest * request, HTResponse * response,
177: char * token, char * value)
2.1 frystyk 178: {
179: char * field;
180: if ((field = HTNextField(&value)) != NULL) {
181: char *lc = field;
182: while ((*lc = TOLOWER(*lc))) lc++;
2.8 frystyk 183: HTResponse_setTransfer(response, HTAtom_for(field));
2.1 frystyk 184: }
185: return HT_OK;
186: }
187:
2.8 frystyk 188: PUBLIC int HTMIME_contentType (HTRequest * request, HTResponse * response,
189: char * token, char * value)
2.1 frystyk 190: {
191: char * field;
192: if ((field = HTNextField(&value)) != NULL) {
2.2 frystyk 193:
194: /* Get the Content-Type */
2.1 frystyk 195: char *lc = field;
196: while ((*lc = TOLOWER(*lc))) lc++;
2.8 frystyk 197: HTResponse_setFormat(response, HTAtom_for(field));
2.2 frystyk 198:
199: /* Get all the parameters to the Content-Type */
200: {
201: char * param;
202: while ((field = HTNextField(&value)) != NULL &&
203: (param = HTNextField(&value)) != NULL) {
204: lc = field;
205: while ((*lc = TOLOWER(*lc))) lc++;
206: lc = param;
207: while ((*lc = TOLOWER(*lc))) lc++;
2.8 frystyk 208: HTResponse_addFormatParam(response, field, param);
2.1 frystyk 209: }
210: }
211: }
212: return HT_OK;
213: }
214:
2.8 frystyk 215: PUBLIC int HTMIME_link (HTRequest * request, HTResponse * response,
216: char * token, char * value)
2.1 frystyk 217: {
218:
219: return HT_OK;
220: }
221:
2.8 frystyk 222: PUBLIC int HTMIME_location (HTRequest * request, HTResponse * response,
223: char * token, char * value)
2.1 frystyk 224: {
2.8 frystyk 225: HTAnchor * redirection = HTAnchor_findAddress(HTStrip(value));
226: HTResponse_setRedirection(response, redirection);
2.1 frystyk 227: return HT_OK;
228: }
229:
2.8 frystyk 230: PUBLIC int HTMIME_maxForwards (HTRequest * request, HTResponse * response,
231: char * token, char * value)
2.1 frystyk 232: {
233:
2.6 frystyk 234: return HT_OK;
235: }
236:
2.8 frystyk 237: PUBLIC int HTMIME_messageDigest (HTRequest * request, HTResponse * response,
238: char * token, char * value)
2.1 frystyk 239: {
2.8 frystyk 240: HTResponse_addChallenge(response, "Digest-MessageDigest", value);
2.1 frystyk 241: return HT_OK;
242: }
243:
2.8 frystyk 244: PUBLIC int HTMIME_pragma (HTRequest * request, HTResponse * response,
245: char * token, char * value)
2.1 frystyk 246: {
2.8 frystyk 247: /*
248: ** Walk through the set of pragma directives and search for one that may
249: ** affect the cachability of this object
2.2 frystyk 250: */
2.8 frystyk 251: char * name_val;
252: while ((name_val = HTNextPair(&value)) != NULL) {
253: char * name = HTNextField(&name_val);
254: if (name) {
255: if (!strcasecomp(name, "no-cache")) {
256: HTResponse_setCachable(response, NO);
257: if (STREAM_TRACE) HTTrace("MIMEParser.. No-Cache Pragma\n");
258: }
259: }
260: }
2.1 frystyk 261: return HT_OK;
262: }
263:
2.8 frystyk 264: PUBLIC int HTMIME_protocol (HTRequest * request, HTResponse * response,
265: char * token, char * value)
2.1 frystyk 266: {
2.8 frystyk 267: char * param = NULL;
268: char * protocol = HTNextSExp(&value, ¶m);
269: if (protocol) {
270: if (PROT_TRACE)
271: HTTrace("Protocol.... Name: `%s\', value: `%s\'\n",
272: protocol, param);
273: HTResponse_addProtocol(response, protocol, param);
274: }
2.6 frystyk 275: return HT_OK;
276: }
277:
2.8 frystyk 278: PUBLIC int HTMIME_protocolInfo (HTRequest * request, HTResponse * response,
279: char * token, char * value)
2.6 frystyk 280: {
2.8 frystyk 281: char * param = NULL;
282: char * info = HTNextSExp(&value, ¶m);
283: if (info) {
284: if (PROT_TRACE)
285: HTTrace("Protocol.... Info: `%s\', value: `%s\'\n",
286: info, param);
287: HTResponse_addProtocolInfo(response, info, param);
288: }
2.1 frystyk 289: return HT_OK;
290: }
291:
2.8 frystyk 292: PUBLIC int HTMIME_protocolRequest (HTRequest * request, HTResponse * response,
293: char * token, char * value)
2.1 frystyk 294: {
2.8 frystyk 295: char * param = NULL;
296: char * preq = HTNextSExp(&value, ¶m);
297: if (preq) {
298: if (PROT_TRACE)
299: HTTrace("Protocol.... Request: `%s\', value: `%s\'\n",
300: preq, param);
301: HTResponse_addProtocolRequest(response, preq, param);
2.7 frystyk 302: }
2.1 frystyk 303: return HT_OK;
304: }
305:
2.8 frystyk 306: PUBLIC int HTMIME_proxyAuthorization (HTRequest * request, HTResponse * response,
307: char * token, char * value)
2.1 frystyk 308: {
309:
310: return HT_OK;
311: }
312:
2.8 frystyk 313: PUBLIC int HTMIME_public (HTRequest * request, HTResponse * response,
314: char * token, char * value)
2.1 frystyk 315: {
2.2 frystyk 316: char * field;
317: HTNet * net = HTRequest_net(request);
318: HTHost * host = HTNet_host(net);
319: while ((field = HTNextField(&value)) != NULL) {
320: HTMethod new_method;
321: /* We treat them as case-insensitive! */
322: if ((new_method = HTMethod_enum(field)) != METHOD_INVALID)
323: HTHost_appendPublicMethods(host, new_method);
324: }
325: if (STREAM_TRACE)
326: HTTrace("MIMEParser.. Public methods: %d\n",
327: HTHost_publicMethods(host));
2.1 frystyk 328: return HT_OK;
329: }
330:
2.8 frystyk 331: PUBLIC int HTMIME_range (HTRequest * request, HTResponse * response,
332: char * token, char * value)
2.1 frystyk 333: {
334:
335: return HT_OK;
336: }
337:
2.8 frystyk 338: PUBLIC int HTMIME_referer (HTRequest * request, HTResponse * response,
339: char * token, char * value)
2.1 frystyk 340: {
341:
342: return HT_OK;
343: }
344:
2.8 frystyk 345: PUBLIC int HTMIME_retryAfter (HTRequest * request, HTResponse * response,
346: char * token, char * value)
2.1 frystyk 347: {
2.8 frystyk 348: HTUserProfile * up = HTRequest_userProfile(request);
349: HTResponse_setRetryTime(response, HTParseTime(value, up, YES));
2.1 frystyk 350: return HT_OK;
351: }
352:
2.8 frystyk 353: PUBLIC int HTMIME_server (HTRequest * request, HTResponse * response,
354: char * token, char * value)
2.2 frystyk 355: {
356: char * field;
357: HTNet * net = HTRequest_net(request);
358: HTHost * host = HTNet_host(net);
359: if ((field = HTNextField(&value)) != NULL)
360: HTHost_setServer(host, field);
361: return HT_OK;
362: }
363:
2.8 frystyk 364: PUBLIC int HTMIME_upgrade (HTRequest * request, HTResponse * response,
365: char * token, char * value)
2.1 frystyk 366: {
367:
368: return HT_OK;
369: }
370:
2.8 frystyk 371: PUBLIC int HTMIME_userAgent (HTRequest * request, HTResponse * response,
372: char * token, char * value)
2.1 frystyk 373: {
2.2 frystyk 374: char * field;
375: HTNet * net = HTRequest_net(request);
376: HTHost * host = HTNet_host(net);
377: if ((field = HTNextField(&value)) != NULL)
378: HTHost_setUserAgent(host, field);
2.1 frystyk 379: return HT_OK;
380: }
381:
2.8 frystyk 382: PUBLIC int HTMIME_vary (HTRequest * request, HTResponse * response,
383: char * token, char * value)
2.1 frystyk 384: {
385:
386: return HT_OK;
387: }
388:
2.8 frystyk 389: PUBLIC int HTMIME_via (HTRequest * request, HTResponse * response,
390: char * token, char * value)
2.1 frystyk 391: {
392:
393: return HT_OK;
394: }
395:
2.8 frystyk 396: PUBLIC int HTMIME_warning (HTRequest * request, HTResponse * response,
397: char * token, char * value)
2.1 frystyk 398: {
2.2 frystyk 399: char * codestr = HTNextField(&value);
400: char * agent = HTNextField(&value);
401: if (codestr && agent) {
402: int code = atoi(codestr);
403: int idx;
404: char * ptr;
405: if (code==10) idx=HTERR_STALE; else
406: if (code==11) idx=HTERR_REVALIDATION_FAILED; else
407: if (code==12) idx=HTERR_DISCONNECTED_CACHE; else
408: if (code==13) idx=HTERR_HEURISTIC_EXPIRATION; else
409: if (code==14) idx=HTERR_TRANSFORMED; else
410: idx=HTERR_CACHE;
411: if ((ptr = strchr(agent, '\r')) != NULL) /* Strip \r and \n */
412: *ptr = '\0';
413: else if ((ptr = strchr(agent, '\n')) != NULL)
414: *ptr = '\0';
415: HTRequest_addError(request, ERR_WARN, NO, idx, agent,
416: (int) strlen(agent), "HTMIME_warning");
417: } else {
418: if (STREAM_TRACE) HTTrace("MIMEParser.. Invalid warning\n");
419: }
2.1 frystyk 420: return HT_OK;
421: }
Webmaster