Annotation of libwww/Library/src/HTMIMImp.c, revision 2.12
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.12 ! eric 6: ** @(#) $Id: HTMIMImp.c,v 2.11 1996/12/07 15:55:46 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.11 frystyk 120: #if 0
2.9 frystyk 121: #ifndef HT_MUX
2.7 frystyk 122: HTNet_setPersistent(net, NO, HT_TP_INTERLEAVE);
2.9 frystyk 123: #else
124: HTNet_setPersistent(net, NO, HT_TP_PIPELINE);
125: #endif
2.11 frystyk 126: #endif
127: if (STREAM_TRACE) HTTrace("MIMEParser.. Close received...\n");
2.7 frystyk 128: } else if (!strcasecomp(name, "keep-alive")) { /* HTTP/1.0 */
129: HTNet * net = HTRequest_net(request);
2.10 frystyk 130: HTHost * host = HTNet_host(net);
131:
132: /*
133: ** In case this is an HTTP/1.1 server sending keep-alive then
134: ** ignore it.
135: */
136: if (HTHost_version(host) < HTTP_11) {
137: HTNet_setPersistent(net, YES, HT_TP_SINGLE);
138: if (STREAM_TRACE) HTTrace("MIMEParser.. HTTP/1.0 Keep Alive\n");
139: } else
140: if (STREAM_TRACE) HTTrace("MIMEParser.. HTTP/1.0 Keep Alive ignored\n");
2.7 frystyk 141: } else
2.8 frystyk 142: HTResponse_addConnection(response, name, val ? val : "");
2.1 frystyk 143: }
144: }
145: return HT_OK;
146: }
147:
2.8 frystyk 148: PUBLIC int HTMIME_contentEncoding (HTRequest * request, HTResponse * response,
149: char * token, char * value)
2.1 frystyk 150: {
151: char * field;
152: while ((field = HTNextField(&value)) != NULL) {
153: char * lc = field;
154: while ((*lc = TOLOWER(*lc))) lc++;
2.8 frystyk 155: HTResponse_addEncoding(response, HTAtom_for(field));
2.1 frystyk 156: }
157: return HT_OK;
158: }
159:
2.8 frystyk 160: PUBLIC int HTMIME_contentLength (HTRequest * request, HTResponse * response,
161: char * token, char * value)
2.1 frystyk 162: {
163: char * field;
164: if ((field = HTNextField(&value)) != NULL)
2.8 frystyk 165: HTResponse_setLength(response, atol(field));
2.1 frystyk 166: return HT_OK;
167: }
168:
2.8 frystyk 169: PUBLIC int HTMIME_contentRange (HTRequest * request, HTResponse * response,
170: char * token, char * value)
2.1 frystyk 171: {
2.2 frystyk 172: char * field;
2.8 frystyk 173: if ((field = HTNextField(&value)))
174: HTResponse_addRange(response, field, value);
2.1 frystyk 175: return HT_OK;
176: }
177:
2.8 frystyk 178: PUBLIC int HTMIME_contentTransferEncoding (HTRequest * request, HTResponse * response,
179: char * token, char * value)
2.1 frystyk 180: {
181: char * field;
182: if ((field = HTNextField(&value)) != NULL) {
183: char *lc = field;
184: while ((*lc = TOLOWER(*lc))) lc++;
2.8 frystyk 185: HTResponse_setTransfer(response, HTAtom_for(field));
2.1 frystyk 186: }
187: return HT_OK;
188: }
189:
2.8 frystyk 190: PUBLIC int HTMIME_contentType (HTRequest * request, HTResponse * response,
191: char * token, char * value)
2.1 frystyk 192: {
193: char * field;
194: if ((field = HTNextField(&value)) != NULL) {
2.2 frystyk 195:
196: /* Get the Content-Type */
2.1 frystyk 197: char *lc = field;
198: while ((*lc = TOLOWER(*lc))) lc++;
2.8 frystyk 199: HTResponse_setFormat(response, HTAtom_for(field));
2.2 frystyk 200:
201: /* Get all the parameters to the Content-Type */
202: {
203: char * param;
204: while ((field = HTNextField(&value)) != NULL &&
205: (param = HTNextField(&value)) != NULL) {
206: lc = field;
207: while ((*lc = TOLOWER(*lc))) lc++;
208: lc = param;
209: while ((*lc = TOLOWER(*lc))) lc++;
2.8 frystyk 210: HTResponse_addFormatParam(response, field, param);
2.1 frystyk 211: }
212: }
2.12 ! eric 213: }
! 214: return HT_OK;
! 215: }
! 216:
! 217: PUBLIC int HTFindInt(char * haystack, char * needle, int deflt)
! 218: {
! 219: char * start = strstr(haystack, needle);
! 220: int value = deflt;
! 221: if (start != NULL) {
! 222: start += strlen(needle);
! 223: while isspace(*start) start++;
! 224: if (isdigit(*start)) {
! 225: char * end = start + 1;
! 226: char save;
! 227: while (isdigit(*end)) end++;
! 228: save = *end;
! 229: *end = 0;
! 230: value = atoi(start);
! 231: *end = save;
! 232: }
! 233: }
! 234: return value;
! 235: }
! 236:
! 237: /* Keep-Alive: timeout=100, max=50
! 238: */
! 239: PUBLIC int HTMIME_keepAlive (HTRequest * request, HTResponse * response,
! 240: char * token, char * value)
! 241: {
! 242: if (value) {
! 243: HTNet * net = HTRequest_net(request);
! 244: HTHost * host = HTNet_host(net);
! 245: HTHost_setReqsPerConnection(host, HTFindInt(value, "max=", 0));
! 246: /* Should one of these be set? Neither are called in Library.
! 247: ** PUBLIC void HTHost_setPersistTimeout (time_t timeout)
! 248: ** PUBLIC void HTHost_setPersistExpires (HTHost * host, time_t expires)
! 249: */
2.1 frystyk 250: }
251: return HT_OK;
252: }
253:
2.8 frystyk 254: PUBLIC int HTMIME_link (HTRequest * request, HTResponse * response,
255: char * token, char * value)
2.1 frystyk 256: {
257:
258: return HT_OK;
259: }
260:
2.8 frystyk 261: PUBLIC int HTMIME_location (HTRequest * request, HTResponse * response,
262: char * token, char * value)
2.1 frystyk 263: {
2.8 frystyk 264: HTAnchor * redirection = HTAnchor_findAddress(HTStrip(value));
265: HTResponse_setRedirection(response, redirection);
2.1 frystyk 266: return HT_OK;
267: }
268:
2.8 frystyk 269: PUBLIC int HTMIME_maxForwards (HTRequest * request, HTResponse * response,
270: char * token, char * value)
2.1 frystyk 271: {
272:
2.6 frystyk 273: return HT_OK;
274: }
275:
2.8 frystyk 276: PUBLIC int HTMIME_messageDigest (HTRequest * request, HTResponse * response,
277: char * token, char * value)
2.1 frystyk 278: {
2.8 frystyk 279: HTResponse_addChallenge(response, "Digest-MessageDigest", value);
2.1 frystyk 280: return HT_OK;
281: }
282:
2.8 frystyk 283: PUBLIC int HTMIME_pragma (HTRequest * request, HTResponse * response,
284: char * token, char * value)
2.1 frystyk 285: {
2.8 frystyk 286: /*
287: ** Walk through the set of pragma directives and search for one that may
288: ** affect the cachability of this object
2.2 frystyk 289: */
2.8 frystyk 290: char * name_val;
291: while ((name_val = HTNextPair(&value)) != NULL) {
292: char * name = HTNextField(&name_val);
293: if (name) {
294: if (!strcasecomp(name, "no-cache")) {
295: HTResponse_setCachable(response, NO);
296: if (STREAM_TRACE) HTTrace("MIMEParser.. No-Cache Pragma\n");
297: }
298: }
299: }
2.1 frystyk 300: return HT_OK;
301: }
302:
2.8 frystyk 303: PUBLIC int HTMIME_protocol (HTRequest * request, HTResponse * response,
304: char * token, char * value)
2.1 frystyk 305: {
2.8 frystyk 306: char * param = NULL;
307: char * protocol = HTNextSExp(&value, ¶m);
308: if (protocol) {
309: if (PROT_TRACE)
310: HTTrace("Protocol.... Name: `%s\', value: `%s\'\n",
311: protocol, param);
312: HTResponse_addProtocol(response, protocol, param);
313: }
2.6 frystyk 314: return HT_OK;
315: }
316:
2.8 frystyk 317: PUBLIC int HTMIME_protocolInfo (HTRequest * request, HTResponse * response,
318: char * token, char * value)
2.6 frystyk 319: {
2.8 frystyk 320: char * param = NULL;
321: char * info = HTNextSExp(&value, ¶m);
322: if (info) {
323: if (PROT_TRACE)
324: HTTrace("Protocol.... Info: `%s\', value: `%s\'\n",
325: info, param);
326: HTResponse_addProtocolInfo(response, info, param);
327: }
2.1 frystyk 328: return HT_OK;
329: }
330:
2.8 frystyk 331: PUBLIC int HTMIME_protocolRequest (HTRequest * request, HTResponse * response,
332: char * token, char * value)
2.1 frystyk 333: {
2.8 frystyk 334: char * param = NULL;
335: char * preq = HTNextSExp(&value, ¶m);
336: if (preq) {
337: if (PROT_TRACE)
338: HTTrace("Protocol.... Request: `%s\', value: `%s\'\n",
339: preq, param);
340: HTResponse_addProtocolRequest(response, preq, param);
2.7 frystyk 341: }
2.1 frystyk 342: return HT_OK;
343: }
344:
2.8 frystyk 345: PUBLIC int HTMIME_proxyAuthorization (HTRequest * request, HTResponse * response,
346: char * token, char * value)
2.1 frystyk 347: {
348:
349: return HT_OK;
350: }
351:
2.8 frystyk 352: PUBLIC int HTMIME_public (HTRequest * request, HTResponse * response,
353: char * token, char * value)
2.1 frystyk 354: {
2.2 frystyk 355: char * field;
356: HTNet * net = HTRequest_net(request);
357: HTHost * host = HTNet_host(net);
358: while ((field = HTNextField(&value)) != NULL) {
359: HTMethod new_method;
360: /* We treat them as case-insensitive! */
361: if ((new_method = HTMethod_enum(field)) != METHOD_INVALID)
362: HTHost_appendPublicMethods(host, new_method);
363: }
364: if (STREAM_TRACE)
365: HTTrace("MIMEParser.. Public methods: %d\n",
366: HTHost_publicMethods(host));
2.1 frystyk 367: return HT_OK;
368: }
369:
2.8 frystyk 370: PUBLIC int HTMIME_range (HTRequest * request, HTResponse * response,
371: char * token, char * value)
2.1 frystyk 372: {
373:
374: return HT_OK;
375: }
376:
2.8 frystyk 377: PUBLIC int HTMIME_referer (HTRequest * request, HTResponse * response,
378: char * token, char * value)
2.1 frystyk 379: {
380:
381: return HT_OK;
382: }
383:
2.8 frystyk 384: PUBLIC int HTMIME_retryAfter (HTRequest * request, HTResponse * response,
385: char * token, char * value)
2.1 frystyk 386: {
2.8 frystyk 387: HTUserProfile * up = HTRequest_userProfile(request);
388: HTResponse_setRetryTime(response, HTParseTime(value, up, YES));
2.1 frystyk 389: return HT_OK;
390: }
391:
2.8 frystyk 392: PUBLIC int HTMIME_server (HTRequest * request, HTResponse * response,
393: char * token, char * value)
2.2 frystyk 394: {
395: char * field;
396: HTNet * net = HTRequest_net(request);
397: HTHost * host = HTNet_host(net);
398: if ((field = HTNextField(&value)) != NULL)
399: HTHost_setServer(host, field);
400: return HT_OK;
401: }
402:
2.8 frystyk 403: PUBLIC int HTMIME_upgrade (HTRequest * request, HTResponse * response,
404: char * token, char * value)
2.1 frystyk 405: {
406:
407: return HT_OK;
408: }
409:
2.8 frystyk 410: PUBLIC int HTMIME_userAgent (HTRequest * request, HTResponse * response,
411: char * token, char * value)
2.1 frystyk 412: {
2.2 frystyk 413: char * field;
414: HTNet * net = HTRequest_net(request);
415: HTHost * host = HTNet_host(net);
416: if ((field = HTNextField(&value)) != NULL)
417: HTHost_setUserAgent(host, field);
2.1 frystyk 418: return HT_OK;
419: }
420:
2.8 frystyk 421: PUBLIC int HTMIME_vary (HTRequest * request, HTResponse * response,
422: char * token, char * value)
2.1 frystyk 423: {
424:
425: return HT_OK;
426: }
427:
2.8 frystyk 428: PUBLIC int HTMIME_via (HTRequest * request, HTResponse * response,
429: char * token, char * value)
2.1 frystyk 430: {
431:
432: return HT_OK;
433: }
434:
2.8 frystyk 435: PUBLIC int HTMIME_warning (HTRequest * request, HTResponse * response,
436: char * token, char * value)
2.1 frystyk 437: {
2.2 frystyk 438: char * codestr = HTNextField(&value);
439: char * agent = HTNextField(&value);
440: if (codestr && agent) {
441: int code = atoi(codestr);
442: int idx;
443: char * ptr;
444: if (code==10) idx=HTERR_STALE; else
445: if (code==11) idx=HTERR_REVALIDATION_FAILED; else
446: if (code==12) idx=HTERR_DISCONNECTED_CACHE; else
447: if (code==13) idx=HTERR_HEURISTIC_EXPIRATION; else
448: if (code==14) idx=HTERR_TRANSFORMED; else
449: idx=HTERR_CACHE;
450: if ((ptr = strchr(agent, '\r')) != NULL) /* Strip \r and \n */
451: *ptr = '\0';
452: else if ((ptr = strchr(agent, '\n')) != NULL)
453: *ptr = '\0';
454: HTRequest_addError(request, ERR_WARN, NO, idx, agent,
455: (int) strlen(agent), "HTMIME_warning");
456: } else {
457: if (STREAM_TRACE) HTTrace("MIMEParser.. Invalid warning\n");
458: }
2.1 frystyk 459: return HT_OK;
460: }
Webmaster