[BACK] Return to HTTP.c CVS log [TXT] [DIR] Up to [Public] / libwww / Library / src

Annotation of libwww/Library/src/HTTP.c, revision 1.32

1.1 timbl 1: /*   HyperText Tranfer Protocol   - Client implementation     HTTP.c
 2: **   ==========================
1.2 timbl 3: **
 4: ** Bugs:
 5: **   Not implemented:
 6: **       Forward
 7: **       Redirection
 8: **       Error handling
1.1 timbl 9: */
 10: 
 11: /*   Module parameters:
 12: **   -----------------
 13: **
 14: ** These may be undefined and redefined by syspec.h
 15: */
1.2 timbl 16: 
 17: /* Implements:
 18: */
 19: #include "HTTP.h"
 20: 
 21: #define HTTP_VERSION  "HTTP/1.0"
 22: #define HTTP2             /* Version is greater than 0.9 */
 23: 
 24: #define INIT_LINE_SIZE     1024  /* Start with line buffer this big */
 25: #define LINE_EXTEND_THRESH   256   /* Minimum read size */
 26: #define VERSION_LENGTH         20   /* for returned protocol version */
 27: 
 28: /* Uses:
 29: */
1.1 timbl 30: #include "HTParse.h"
 31: #include "HTUtils.h"
 32: #include "tcp.h"
 33: #include "HTTCP.h"
 34: #include "HTFormat.h"
1.2 timbl 35: #include <ctype.h>
 36: #include "HTAlert.h"
 37: #include "HTMIME.h"
1.5 timbl 38: #include "HTML.h"       /* SCW */
 39: #include "HTInit.h"      /* SCW */
1.21 luotonen 40: #include "HTAccess.h"     /* HTRequest */
1.14 luotonen 41: #include "HTAABrow.h"     /* Access Authorization */
1.20 timbl 42: #include "HTTee.h"       /* Tee off a cache stream */
 43: #include "HTFWriter.h"     /* Write to cache file */
1.1 timbl 44: 
1.2 timbl 45: struct _HTStream {
 46:    HTStreamClass * isa;      /* all we need to know */
 47: };
 48: 
1.6 timbl 49: extern char * HTAppName;    /* Application name: please supply */
 50: extern char * HTAppVersion;  /* Application version: please supply */
 51: 
1.19 timbl 52: PUBLIC BOOL HTCacheHTTP = YES; /* Enable caching of HTTP-retrieved files */
1.23 luotonen 53: 
 54: 
1.21 luotonen 55: PRIVATE void parse_401_headers ARGS2(HTRequest *,   req,
 56:                   HTInputSocket *,  isoc)
 57: {
 58:   HTAAScheme scheme;
 59:   char *line;
 60:   int num_schemes = 0;
 61:   HTList *valid_schemes = HTList_new();
 62:   HTAssocList **scheme_specifics = NULL;
 63:   char *template = NULL;
 64: 
 65:   /* Read server reply header lines */
 66: 
 67:   if (TRACE)
 68:    fprintf(stderr, "Server 401 reply header lines:\n");
 69: 
 70:   while (NULL != (line = HTInputSocket_getUnfoldedLine(isoc)) &&
 71:      *line != 0) {
 72: 
 73:    if (TRACE) fprintf(stderr, "%s\n", line);
 74: 
 75:    if (strchr(line, ':')) {    /* Valid header line */
 76: 
 77:      char *p = line;
 78:      char *fieldname = HTNextField(&p);
 79:      char *arg1 = HTNextField(&p);
 80:      char *args = p;
 81:      
 82:      if (0==strcasecomp(fieldname, "WWW-Authenticate:")) {
 83:        if (HTAA_UNKNOWN != (scheme = HTAAScheme_enum(arg1))) {
 84:          HTList_addObject(valid_schemes, (void*)scheme);
 85:          if (!scheme_specifics) {
 86:            int i;
 87:            scheme_specifics = (HTAssocList**)
 88:              malloc(HTAA_MAX_SCHEMES * sizeof(HTAssocList*));
 89:            if (!scheme_specifics)
 90:              outofmem(__FILE__, "parse_401_headers");
 91:            for (i=0; i < HTAA_MAX_SCHEMES; i++)
 92:              scheme_specifics[i] = NULL;
 93:          }
 94:          scheme_specifics[scheme] = HTAA_parseArgList(args);
 95:          num_schemes++;
 96:        }
 97:        else if (TRACE) {
 98:          fprintf(stderr, "Unknown scheme `%s' %s\n",
 99:              (arg1 ? arg1 : "(null)"),
 100:              "in WWW-Authenticate: field");
 101:        }
 102:      }
 103: 
 104:      else if (0==strcasecomp(fieldname, "WWW-Protection-Template:")) {
 105:        if (TRACE)
 106:          fprintf(stderr, "Protection template set to `%s'\n", arg1);
 107:        StrAllocCopy(template, arg1);
 108:      }
 109: 
 110:    } /* if a valid header line */
 111:    else if (TRACE) {
 112:      fprintf(stderr, "Invalid header line `%s' ignored\n", line);
 113:    } /* else invalid header line */
 114:   } /* while header lines remain */
 115: 
 116:   req->valid_schemes = valid_schemes;
 117:   req->scheme_specifics = scheme_specifics;
 118:   req->prot_template = template;
 119: }
 120: 
 121: 
 122: 
1.1 timbl 123: /*       Load Document from HTTP Server         HTLoadHTTP()
 124: **       ==============================
 125: **
 126: **   Given a hypertext address, this routine loads a document.
 127: **
 128: **
 129: ** On entry,
 130: **   arg   is the hypertext reference of the article to be loaded.
 131: **
 132: ** On exit,
 133: **   returns >=0   If no error, a good socket number
 134: **       <0   Error.
 135: **
 136: **   The socket must be closed by the caller after the document has been
 137: **   read.
 138: **
 139: */
1.19 timbl 140: PUBLIC int HTLoadHTTP ARGS1 (HTRequest *, request)
1.1 timbl 141: {
1.22 luotonen 142:   CONST char * arg = NULL;
1.1 timbl 143:   int s;               /* Socket number for returned data */
 144:   int status;                /* tcp return */
1.10 timbl 145:   char crlf[3];           /* A CR LF equivalent string */
1.3 timbl 146:   HTStream * target = NULL;     /* Unconverted data */
 147:   
1.2 timbl 148:   CONST char* gate = 0;       /* disable this feature */
1.1 timbl 149:   SockA soc_address;         /* Binary network address */
 150:   SockA * sin = &soc_address;
1.2 timbl 151:   BOOL extensions = YES;       /* Assume good HTTP server */
1.27 luotonen 152:   char * cache_file_name = NULL;
1.17 timbl 153: 
1.22 luotonen 154:   if (request->reason == HTAA_OK_GATEWAY) {
 155:    arg = request->translated;
1.23 luotonen 156: 
 157:    /*
 158:    ** Cache lookup
 159:    */
1.29 luotonen 160: #ifdef NOT_USED_YET
1.27 luotonen 161:    if (request->method == METHOD_GET &&
 162:      !request->authorization &&
 163:      !request->arg_keywords) {
1.23 luotonen 164: 
1.27 luotonen 165:      if (HTCacheLookupOrCreate(arg, &cache_file_name)) {
1.23 luotonen 166: 
1.27 luotonen 167:        FILE * cache_file = fopen(cache_file_name, "r");
1.23 luotonen 168: 
1.27 luotonen 169:        if (cache_file) {
 170:          HTFileCopy(cache_file, request->output_stream);
 171:          fclose(cache_file);
 172:          free(cache_file_name);
 173:          (*request->output_stream->isa->free)(request->output_stream);
 174:          return HT_LOADED;
 175:        }
 176:        free(cache_file_name);
 177:        cache_file_name = NULL;
 178:      } /* Cache lookup */
 179:    } /* Can use cache? */
1.29 luotonen 180: #endif /* NOT_USED_YET */
1.27 luotonen 181:   } /* I'm a gateway */
1.22 luotonen 182:   else {
 183:    arg = HTAnchor_physical(request->anchor);
 184:    StrAllocCopy(request->argument, arg);
 185:   }
 186: 
1.1 timbl 187:   if (!arg) return -3;        /* Bad if no name sepcified   */
 188:   if (!*arg) return -2;       /* Bad if name had zero length */
 189: 
 190: /* Set up defaults:
 191: */
 192: #ifdef DECNET
1.2 timbl 193:   sin->sdn_family = AF_DECnet;      /* Family = DECnet, host order */
 194:   sin->sdn_objnum = DNP_OBJ;     /* Default: http object number */
1.1 timbl 195: #else /* Internet */
1.2 timbl 196:   sin->sin_family = AF_INET;   /* Family = internet, host order */
 197:   sin->sin_port = htons(TCP_PORT);  /* Default: http port  */
1.1 timbl 198: #endif
 199: 
1.10 timbl 200:   sprintf(crlf, "%c%c", CR, LF);   /* To be corect on Mac, VM, etc */
 201:   
1.1 timbl 202:   if (TRACE) {
 203:     if (gate) fprintf(stderr,
 204:        "HTTPAccess: Using gateway %s for %s\n", gate, arg);
 205:     else fprintf(stderr, "HTTPAccess: Direct access for %s\n", arg);
 206:   }
 207:   
 208: /* Get node name and optional port number:
 209: */
 210:   {
 211:    char *p1 = HTParse(gate ? gate : arg, "", PARSE_HOST);
 212:    int status = HTParseInet(sin, p1); /* TBL 920622 */
 213:     free(p1);
 214:    if (status) return status;  /* No such host for example */
 215:   }
 216:   
1.15 luotonen 217: /*
 218: ** Compose authorization information (this was moved here
 219: ** from after the making of the connection so that the connection
 220: ** wouldn't have to wait while prompting username and password
 221: ** from the user).               -- AL 13.10.93
 222: */
 223: #ifdef ACCESS_AUTH
1.21 luotonen 224:   HTAA_composeAuth(request);
 225:   if (TRACE) {
 226:    if (request->authorization)
 227:      fprintf(stderr, "HTTP: Sending Authorization: %s\n",
 228:          request->authorization);
 229:    else
 230:      fprintf(stderr, "HTTP: Not sending authorization (yet)\n");
1.15 luotonen 231:   }
 232: #endif /* ACCESS_AUTH */
1.1 timbl 233:  
1.10 timbl 234: /*   Now, let's get a socket set up from the server for the data:
1.1 timbl 235: */   
 236: #ifdef DECNET
 237:   s = socket(AF_DECnet, SOCK_STREAM, 0);
 238: #else
 239:   s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 240: #endif
 241:   status = connect(s, (struct sockaddr*)&soc_address, sizeof(soc_address));
 242:   if (status < 0) {
 243:      if (TRACE) fprintf(stderr, 
1.30 frystyk 244:       "HTTP: Unable to connect to remote host for `%s' (errno = %d).\n",
 245:       arg, errno);
1.17 timbl 246: 
1.1 timbl 247:      return HTInetStatus("connect");
 248:    }
 249:   
 250:   if (TRACE) fprintf(stderr, "HTTP connected, socket %d\n", s);
 251: 
1.17 timbl 252: 
 253: /*   Compose and send command
 254: **   ------------------------
 255: */
 256:   {
 257:     char *command;         /* The whole command */
 258:    
1.1 timbl 259: /*   Ask that node for the document,
 260: **   omitting the host name & anchor if not gatewayed.
 261: */    
1.17 timbl 262:    if (gate) {
 263:      command = malloc(4 + strlen(arg)+ 2 + 31);
 264:      if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
 265:      strcpy(command, "GET ");
 266:      strcat(command, arg);
 267:    } else { /* not gatewayed */
 268:      char * p1 = HTParse(arg, "", PARSE_PATH|PARSE_PUNCTUATION);
 269:      command = malloc(4 + strlen(p1)+ 2 + 31);
 270:      if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
1.23 luotonen 271:      if (request->method != METHOD_INVALID) {
 272:        strcpy(command, HTMethod_name(request->method));
1.22 luotonen 273:        strcat(command, " ");
 274:      }
 275:      else {
 276:        strcpy(command, "GET ");
 277:      }
1.17 timbl 278:      strcat(command, p1);
 279:      free(p1);
 280:    }
1.2 timbl 281: #ifdef HTTP2
1.17 timbl 282:    if (extensions) {
 283:      strcat(command, " ");
 284:      strcat(command, HTTP_VERSION);
 285:    }
1.2 timbl 286: #endif
1.17 timbl 287:   
 288:    strcat(command, crlf); /* CR LF, as in rfc 977 */
 289:   
 290:    if (extensions) {
1.21 luotonen 291: 
1.17 timbl 292:      int i;
 293:      HTAtom * present = WWW_PRESENT;
 294:      char line[256];  /*@@@@ */
1.21 luotonen 295:      HTList *conversions[2];
 296: 
1.22 luotonen 297:      if (!HTConversions) {
 298:        HTConversions = HTList_new();
 299:        HTFormatInit(HTConversions);
 300:      }
1.28 timbl 301: 
1.21 luotonen 302:      conversions[0] = HTConversions;
 303:      conversions[1] = request->conversions;
 304: 
 305:      for (i=0; i<2; i++) {
 306:        HTList *cur = conversions[i];
 307:        HTPresentation *pres;
 308: 
 309:        while ((pres = (HTPresentation*)HTList_nextObject(cur))) {
 310:          if (pres->rep_out == present) {
 311:            if (pres->quality != 1.0) {
 312:              sprintf(line, "Accept: %s q=%.3f%c%c",
 313:                  HTAtom_name(pres->rep),
 314:                  pres->quality, CR, LF);
 315:            } else {
 316:              sprintf(line, "Accept: %s%c%c",
 317:                  HTAtom_name(pres->rep), CR, LF);
 318:            }
 319:            StrAllocCat(command, line);
1.17 timbl 320:          }
 321:        }
1.2 timbl 322:      }
1.22 luotonen 323: 
 324:      sprintf(line, "User-Agent: %s%s %s/%s libwww/%s%c%c",
 325:          request->user_agent ? request->user_agent : "",
 326:          request->user_agent ? " VIA Gateway" : "",
1.17 timbl 327:          HTAppName ? HTAppName : "unknown",
 328:          HTAppVersion ? HTAppVersion : "0.0",
 329:          HTLibraryVersion, CR, LF);
 330:          StrAllocCat(command, line);
 331:   
1.22 luotonen 332:      if (request->from) {
 333:        sprintf(line, "From: %s%c%c", request->from, CR, LF);
 334:        StrAllocCat(command, line);
 335:      }
 336: 
1.14 luotonen 337: #ifdef ACCESS_AUTH
1.21 luotonen 338:      if (request->authorization != NULL) {
 339:        sprintf(line, "Authorization: %s%c%c",
 340:            request->authorization, CR, LF);
1.17 timbl 341:        StrAllocCat(command, line);
 342:      }
 343: #endif /* ACCESS_AUTH */
1.22 luotonen 344: 
 345:      if (request->content_type) {
 346:        sprintf(line, "Content-Type: %s%c%c",
 347:            HTAtom_name(request->content_type), CR, LF);
 348:        StrAllocCat(command, line);
 349:      }
 350: 
 351:      if (request->content_length > 0) {
 352:        sprintf(line, "Content-Length: %d%c%c",
 353:            request->content_length, CR, LF);
 354:        StrAllocCat(command, line);
 355:      }
 356: 
 357: 
1.14 luotonen 358:    }
1.17 timbl 359:   
 360:    StrAllocCat(command, crlf);   /* Blank line means "end" */
 361:   
 362:    if (TRACE) fprintf(stderr, "HTTP Tx: %s\n", command);
 363:   
 364:   /* Translate into ASCII if necessary
 365:   */
1.4 timbl 366: #ifdef NOT_ASCII
1.17 timbl 367:    {
 368:      char * p;
 369:      for(p = command; *p; p++) {
 370:        *p = TOASCII(*p);
 371:      }
1.1 timbl 372:    }
1.3 timbl 373: #endif
1.17 timbl 374:   
 375:    status = NETWRITE(s, command, (int)strlen(command));
 376:    free(command);
 377:    if (status<0) {
 378:      if (TRACE) fprintf(stderr,
 379:        "HTTPAccess: Unable to send command.\n");
1.1 timbl 380:      return HTInetStatus("send");
1.17 timbl 381:    }
 382:   } /* compose and send command */
 383:   
1.2 timbl 384: 
1.17 timbl 385: /*   Read the response
 386: **   -----------------
1.11 timbl 387: **
 388: **   HTTP0 servers must return ASCII style text, though it can in
 389: **   principle be just text without any markup at all.
 390: **   Full HTTP servers must return a response
 391: **   line and RFC822 style header. The response must therefore in
 392: **   either case have a CRLF somewhere soon.
 393: **
 394: **   This is the theory. In practice, there are (1993) unfortunately
 395: **   many binary documents just served up with HTTP0.9. This
 396: **   means we have to preserve the binary buffer (on the assumption that
 397: **   conversion from ASCII may lose information) in case it turns
 398: **   out that we want the binary original.
1.2 timbl 399: */
1.3 timbl 400: 
1.22 luotonen 401:   if (request->reason == HTAA_OK_GATEWAY) {
1.24 luotonen 402: 
1.22 luotonen 403:    /*
 404:    ** Server as a gateway -- send body of the message
 405:    ** received from client (if any).
 406:    */
 407:    if (request->isoc && request->content_length > 0) {
 408:      int remain = request->content_length;
 409:      int i = remain;
 410:      char * buf;
 411: 
 412:      while (remain > 0 &&
 413:          (buf = HTInputSocket_getBlock(request->isoc, &i))) {
 414:        int status = NETWRITE(s, buf, i);
 415:        if (status < 0) {
1.27 luotonen 416:          CTRACE(stderr, "HTTPAccess.. Unable to forward body\n");
1.22 luotonen 417:          return HTInetStatus("send");
 418:        }
 419:        remain -= i;
 420:        i = remain;
 421:      }
 422:    }
1.23 luotonen 423: 
 424:    /*
 425:    ** Cache the document if it a GET request,
 426:    ** not protected and not a search request.
 427:    */
1.27 luotonen 428:    if (cache_file_name) {
 429:      FILE * cache_file = fopen(cache_file_name, "w");
1.23 luotonen 430: 
1.27 luotonen 431:      if (cache_file) {
 432:        request->output_stream = HTTee(request->output_stream,
1.31 frystyk 433:                        HTFWriter_new(cache_file, NO));
1.27 luotonen 434:        CTRACE(stderr, "Gateway..... writing to cache file\n");
 435:      }
 436:      else {
1.29 luotonen 437: #ifdef NOT_USED_YET
1.27 luotonen 438:        HTCacheCancel(arg);
1.29 luotonen 439: #endif /* NOT_USED_YET */
1.27 luotonen 440:        free(cache_file_name);
 441:        cache_file_name = NULL;
 442:        CTRACE(stderr, "Gateway..... couldn't create cache file\n");
1.23 luotonen 443:      }
 444:    }
1.27 luotonen 445:    else CTRACE(stderr, "Gateway..... not caching\n");
1.23 luotonen 446: 
1.22 luotonen 447:    /*
 448:    ** Load results directly to client
 449:    */
 450:    HTCopy(s, request->output_stream);
1.25 luotonen 451:    (*request->output_stream->isa->free)(request->output_stream);
1.27 luotonen 452:    if (cache_file_name) {
1.29 luotonen 453: #ifdef NOT_USED_YET
1.27 luotonen 454:      HTCacheCreated(arg, (time_t)0);
1.29 luotonen 455: #endif /* NOT_USED_YET */
1.27 luotonen 456:      free(cache_file_name);
1.24 luotonen 457:    }
1.22 luotonen 458:    return HT_LOADED;
 459:   }
 460:   else {   /* read response */
1.21 luotonen 461: 
1.17 timbl 462:    HTFormat format_in;       /* Format arriving in the message */
1.21 luotonen 463:    HTInputSocket *isoc = HTInputSocket_new(s);
 464:    char * status_line = HTInputSocket_getStatusLine(isoc);
1.2 timbl 465: 
1.11 timbl 466: /* Kludge to trap binary responses from illegal HTTP0.9 servers.
 467: ** First time we have enough, look at the stub in ASCII
 468: ** and get out of here if it doesn't look right.
 469: **
 470: ** We also check for characters above 128 in the first few bytes, and
 471: ** if we find them we forget the html default.
 472: **
 473: ** Bugs: A HTTP0.9 server returning a document starting "HTTP/"
 474: **   will be taken as a HTTP 1.0 server. Failure.
 475: **   An HTTP 0.9 server returning a binary document with
 476: **   characters < 128 will be read as ASCII.
 477: */
1.21 luotonen 478:    if (!status_line) {   /* HTTP0 response */
 479:      if (HTInputSocket_seemsBinary(isoc)) {
 480:        format_in = HTAtom_for("www/unknown");
 481:      }
 482:      else {
 483:        format_in = WWW_HTML;
 484:      }
 485:      goto copy;
 486:    } /* end kludge */
 487: 
 488:    if (status_line) {   /* Decode full HTTP response */
 489:      /*
 490:      ** We now have a terminated server status line, and we have
 491:      ** checked that it is most probably a legal one. Parse it.
 492:      */
 493:      char server_version[VERSION_LENGTH+1];
 494:      int server_status;
 495: 
 496:      if (TRACE)
 497:        fprintf(stderr, "HTTP Status Line: Rx: %.70s\n", status_line);
1.17 timbl 498:   
1.21 luotonen 499:      sscanf(status_line, "%20s%d", server_version, &server_status);
1.2 timbl 500: 
1.21 luotonen 501:      format_in = HTAtom_for("www/mime");
1.7 timbl 502:   
1.21 luotonen 503:      switch (server_status / 100) {
1.2 timbl 504: 
1.21 luotonen 505:       default:     /* bad number */
 506:        HTAlert("Unknown status reply from server!");
 507:        break;
1.17 timbl 508:          
1.21 luotonen 509:       case 3:      /* Various forms of redirection */
 510:        HTAlert(
1.17 timbl 511:      "Redirection response from server is not handled by this client");
1.21 luotonen 512:        break;
1.17 timbl 513:          
1.21 luotonen 514:       case 4:      /* Access Authorization problem */
1.14 luotonen 515: #ifdef ACCESS_AUTH
1.21 luotonen 516:        switch (server_status) {
 517:         case 401:
 518:          parse_401_headers(request, isoc);
 519: 
 520:          if (TRACE) fprintf(stderr, "%s %d %s\n",
 521:                    "HTTP: close socket", s,
 522:                    "to retry with Access Authorization");
 523:          HTInputSocket_free(isoc);
 524:          (void)NETCLOSE(s);
1.24 luotonen 525:          if (HTAA_retryWithAuth(request, HTLoadHTTP)) {
1.21 luotonen 526:            status = HT_LOADED;/* @@ THIS ONLY WORKS ON LINEMODE */
 527:            goto clean_up;
 528:          }
 529:          /* else falltrough */
 530:         default:
1.14 luotonen 531:          {
1.21 luotonen 532:            char *p1 = HTParse(gate ? gate : arg, "",
 533:                      PARSE_HOST);
 534:            char * message;
 535: 
 536:            if (!(message = (char*)malloc(strlen(status_line) +
 537:                           strlen(p1) + 100)))
 538:              outofmem(__FILE__, "HTTP 4xx status");
1.14 luotonen 539:            sprintf(message,
1.21 luotonen 540:                "HTTP server at %s replies:\n%s\n\n%s\n",
 541:                p1, status_line,
 542:                ((server_status == 401) 
 543:                 ? "Access Authorization package giving up.\n"
 544:                 : ""));
1.22 luotonen 545:            status = HTLoadError(request, server_status, message);
1.14 luotonen 546:            free(message);
 547:            free(p1);
 548:            goto clean_up;
 549:          }
1.21 luotonen 550:        } /* switch */
 551:        goto clean_up;
 552:        break;
 553: #else
 554:        /* case 4 without Access Authorization falls through */
 555:        /* to case 5 (previously "I think I goofed"). -- AL */
 556: #endif /* ACCESS_AUTH */
 557: 
 558:       case 5:      /* I think you goofed */
 559:        {
 560:          char *p1 = HTParse(gate ? gate : arg, "", PARSE_HOST);
 561:          char * message = (char*)malloc(strlen(status_line) + 
 562:                          strlen(p1) + 100);
 563:          if (!message) outofmem(__FILE__, "HTTP 5xx status");
 564:          sprintf(message,
 565:              "HTTP server at %s replies:\n%s", p1, status_line);
1.22 luotonen 566:          status = HTLoadError(request, server_status, message);
1.21 luotonen 567:          free(message);
 568:          free(p1);
 569:          goto clean_up;
 570:        }
 571:        break;
1.17 timbl 572:          
1.21 luotonen 573:       case 2:      /* Good: Got MIME object */
 574:        break;
1.17 timbl 575:   
1.21 luotonen 576:      } /* switch on response code */
1.17 timbl 577:      
1.21 luotonen 578:    } /* Full HTTP reply */
1.17 timbl 579:      
 580:   
1.3 timbl 581: /*   Set up the stream stack to handle the body of the message
 582: */
1.21 luotonen 583: 
1.13 duns 584: copy:
1.21 luotonen 585: 
1.18 timbl 586:    target = HTStreamStack(format_in, request);
1.21 luotonen 587: 
1.17 timbl 588:    if (!target) {
 589:      char buffer[1024]; /* @@@@@@@@ */
 590:      sprintf(buffer, "Sorry, no known way of converting %s to %s.",
 591:          HTAtom_name(format_in), HTAtom_name(request->output_format));
 592:      fprintf(stderr, "HTTP: %s", buffer);
1.22 luotonen 593:      status = HTLoadError(request, 501, buffer);
1.17 timbl 594:      goto clean_up;
 595:    }
 596:   
1.19 timbl 597:     /* @@ Bug: The decision of whether or not to cache should also be
1.21 luotonen 598:    ** made contingent on a IP address match or non match.
 599:    */
1.19 timbl 600:     if (HTCacheHTTP) {
 601:      target = HTTee(target, HTCacheWriter(request, NULL, format_in,
1.21 luotonen 602:                         request->output_format,
 603:                         request->output_stream));
1.19 timbl 604:    }
 605:    
1.11 timbl 606: /*   Push the data down the stream
1.3 timbl 607: **   We have to remember the end of the first buffer we just read
1.2 timbl 608: */
1.30 frystyk 609:    if (format_in == WWW_HTML) { 
1.17 timbl 610:      target = HTNetToText(target);    /* Pipe through CR stripper */
 611:    }
1.21 luotonen 612: 
1.17 timbl 613:    (*target->isa->put_block)(target,
1.21 luotonen 614:                 isoc->input_pointer,
 615:                 isoc->input_limit - isoc->input_pointer);
 616:    HTInputSocket_free(isoc);
1.17 timbl 617:    HTCopy(s, target);
 618:      
 619:    (*target->isa->free)(target);
 620:    status = HT_LOADED;
1.11 timbl 621:   
1.2 timbl 622: /*   Clean up
1.1 timbl 623: */
1.17 timbl 624:    
 625: clean_up: 
 626:    if (TRACE) fprintf(stderr, "HTTP: close socket %d.\n", s);
 627:    (void) NETCLOSE(s);
 628:   
 629:    return status;         /* Good return */
1.3 timbl 630:   
1.17 timbl 631:   } /* read response */
 632: } /* load HTTP */
1.1 timbl 633: 
 634: /*   Protocol descriptor
 635: */
 636: 
1.17 timbl 637: GLOBALDEF PUBLIC HTProtocol HTTP = { "http", HTLoadHTTP, 0, 0 };
1.21 luotonen 638: 

Webmaster

AltStyle によって変換されたページ (->オリジナル) /