Annotation of libwww/Library/src/HTMIMImp.c, revision 2.8.2.2

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

Webmaster