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

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

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.25 luotonen 49: #ifdef NeXT
1.26 luotonen 50: #include "sys/types.h"
 51: #include "sys/stat.h"
1.25 luotonen 52: #define S_ISDIR(m) (m & S_IFDIR)
 53: #define S_ISREG(m) (m & S_IFREG)
 54: #endif
1.2 timbl 55: 
1.6 timbl 56: extern char * HTAppName;    /* Application name: please supply */
 57: extern char * HTAppVersion;  /* Application version: please supply */
 58: 
1.19 timbl 59: PUBLIC BOOL HTCacheHTTP = YES; /* Enable caching of HTTP-retrieved files */
1.23 luotonen 60: 
 61: 
1.21 luotonen 62: PRIVATE void parse_401_headers ARGS2(HTRequest *,   req,
 63:                   HTInputSocket *,  isoc)
 64: {
 65:   HTAAScheme scheme;
 66:   char *line;
 67:   int num_schemes = 0;
 68:   HTList *valid_schemes = HTList_new();
 69:   HTAssocList **scheme_specifics = NULL;
 70:   char *template = NULL;
 71: 
 72:   /* Read server reply header lines */
 73: 
 74:   if (TRACE)
 75:    fprintf(stderr, "Server 401 reply header lines:\n");
 76: 
 77:   while (NULL != (line = HTInputSocket_getUnfoldedLine(isoc)) &&
 78:      *line != 0) {
 79: 
 80:    if (TRACE) fprintf(stderr, "%s\n", line);
 81: 
 82:    if (strchr(line, ':')) {    /* Valid header line */
 83: 
 84:      char *p = line;
 85:      char *fieldname = HTNextField(&p);
 86:      char *arg1 = HTNextField(&p);
 87:      char *args = p;
 88:      
 89:      if (0==strcasecomp(fieldname, "WWW-Authenticate:")) {
 90:        if (HTAA_UNKNOWN != (scheme = HTAAScheme_enum(arg1))) {
 91:          HTList_addObject(valid_schemes, (void*)scheme);
 92:          if (!scheme_specifics) {
 93:            int i;
 94:            scheme_specifics = (HTAssocList**)
 95:              malloc(HTAA_MAX_SCHEMES * sizeof(HTAssocList*));
 96:            if (!scheme_specifics)
 97:              outofmem(__FILE__, "parse_401_headers");
 98:            for (i=0; i < HTAA_MAX_SCHEMES; i++)
 99:              scheme_specifics[i] = NULL;
 100:          }
 101:          scheme_specifics[scheme] = HTAA_parseArgList(args);
 102:          num_schemes++;
 103:        }
 104:        else if (TRACE) {
 105:          fprintf(stderr, "Unknown scheme `%s' %s\n",
 106:              (arg1 ? arg1 : "(null)"),
 107:              "in WWW-Authenticate: field");
 108:        }
 109:      }
 110: 
 111:      else if (0==strcasecomp(fieldname, "WWW-Protection-Template:")) {
 112:        if (TRACE)
 113:          fprintf(stderr, "Protection template set to `%s'\n", arg1);
 114:        StrAllocCopy(template, arg1);
 115:      }
 116: 
 117:    } /* if a valid header line */
 118:    else if (TRACE) {
 119:      fprintf(stderr, "Invalid header line `%s' ignored\n", line);
 120:    } /* else invalid header line */
 121:   } /* while header lines remain */
 122: 
 123:   req->valid_schemes = valid_schemes;
 124:   req->scheme_specifics = scheme_specifics;
 125:   req->prot_template = template;
 126: }
 127: 
 128: 
 129: 
1.1 timbl 130: /*       Load Document from HTTP Server         HTLoadHTTP()
 131: **       ==============================
 132: **
 133: **   Given a hypertext address, this routine loads a document.
 134: **
 135: **
 136: ** On entry,
 137: **   arg   is the hypertext reference of the article to be loaded.
 138: **
 139: ** On exit,
 140: **   returns >=0   If no error, a good socket number
 141: **       <0   Error.
 142: **
 143: **   The socket must be closed by the caller after the document has been
 144: **   read.
 145: **
 146: */
1.19 timbl 147: PUBLIC int HTLoadHTTP ARGS1 (HTRequest *, request)
1.1 timbl 148: {
1.22 luotonen 149:   CONST char * arg = NULL;
1.1 timbl 150:   int s;               /* Socket number for returned data */
 151:   int status;                /* tcp return */
1.10 timbl 152:   char crlf[3];           /* A CR LF equivalent string */
1.3 timbl 153:   HTStream * target = NULL;     /* Unconverted data */
 154:   
1.2 timbl 155:   CONST char* gate = 0;       /* disable this feature */
1.1 timbl 156:   SockA soc_address;         /* Binary network address */
 157:   SockA * sin = &soc_address;
1.2 timbl 158:   BOOL extensions = YES;       /* Assume good HTTP server */
1.27 luotonen 159:   char * cache_file_name = NULL;
1.17 timbl 160: 
1.22 luotonen 161:   if (request->reason == HTAA_OK_GATEWAY) {
 162:    arg = request->translated;
1.23 luotonen 163: 
 164:    /*
 165:    ** Cache lookup
 166:    */
1.27 luotonen 167:    if (request->method == METHOD_GET &&
 168:      !request->authorization &&
 169:      !request->arg_keywords) {
1.23 luotonen 170: 
1.27 luotonen 171:      if (HTCacheLookupOrCreate(arg, &cache_file_name)) {
1.23 luotonen 172: 
1.27 luotonen 173:        FILE * cache_file = fopen(cache_file_name, "r");
1.23 luotonen 174: 
1.27 luotonen 175:        if (cache_file) {
 176:          HTFileCopy(cache_file, request->output_stream);
 177:          fclose(cache_file);
 178:          free(cache_file_name);
 179:          (*request->output_stream->isa->free)(request->output_stream);
 180:          return HT_LOADED;
 181:        }
 182:        free(cache_file_name);
 183:        cache_file_name = NULL;
 184:      } /* Cache lookup */
 185:    } /* Can use cache? */
 186:   } /* I'm a gateway */
1.22 luotonen 187:   else {
 188:    arg = HTAnchor_physical(request->anchor);
 189:    StrAllocCopy(request->argument, arg);
 190:   }
 191: 
1.1 timbl 192:   if (!arg) return -3;        /* Bad if no name sepcified   */
 193:   if (!*arg) return -2;       /* Bad if name had zero length */
 194: 
 195: /* Set up defaults:
 196: */
 197: #ifdef DECNET
1.2 timbl 198:   sin->sdn_family = AF_DECnet;      /* Family = DECnet, host order */
 199:   sin->sdn_objnum = DNP_OBJ;     /* Default: http object number */
1.1 timbl 200: #else /* Internet */
1.2 timbl 201:   sin->sin_family = AF_INET;   /* Family = internet, host order */
 202:   sin->sin_port = htons(TCP_PORT);  /* Default: http port  */
1.1 timbl 203: #endif
 204: 
1.10 timbl 205:   sprintf(crlf, "%c%c", CR, LF);   /* To be corect on Mac, VM, etc */
 206:   
1.1 timbl 207:   if (TRACE) {
 208:     if (gate) fprintf(stderr,
 209:        "HTTPAccess: Using gateway %s for %s\n", gate, arg);
 210:     else fprintf(stderr, "HTTPAccess: Direct access for %s\n", arg);
 211:   }
 212:   
 213: /* Get node name and optional port number:
 214: */
 215:   {
 216:    char *p1 = HTParse(gate ? gate : arg, "", PARSE_HOST);
 217:    int status = HTParseInet(sin, p1); /* TBL 920622 */
 218:     free(p1);
 219:    if (status) return status;  /* No such host for example */
 220:   }
 221:   
1.15 luotonen 222: /*
 223: ** Compose authorization information (this was moved here
 224: ** from after the making of the connection so that the connection
 225: ** wouldn't have to wait while prompting username and password
 226: ** from the user).               -- AL 13.10.93
 227: */
 228: #ifdef ACCESS_AUTH
1.21 luotonen 229:   HTAA_composeAuth(request);
 230:   if (TRACE) {
 231:    if (request->authorization)
 232:      fprintf(stderr, "HTTP: Sending Authorization: %s\n",
 233:          request->authorization);
 234:    else
 235:      fprintf(stderr, "HTTP: Not sending authorization (yet)\n");
1.15 luotonen 236:   }
 237: #endif /* ACCESS_AUTH */
1.1 timbl 238:  
1.10 timbl 239: /*   Now, let's get a socket set up from the server for the data:
1.1 timbl 240: */   
 241: #ifdef DECNET
 242:   s = socket(AF_DECnet, SOCK_STREAM, 0);
 243: #else
 244:   s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 245: #endif
 246:   status = connect(s, (struct sockaddr*)&soc_address, sizeof(soc_address));
 247:   if (status < 0) {
 248:      if (TRACE) fprintf(stderr, 
 249:       "HTTP: Unable to connect to remote host for `%s' (errno = %d).\n", arg, errno);
1.17 timbl 250: 
1.1 timbl 251:      return HTInetStatus("connect");
 252:    }
 253:   
 254:   if (TRACE) fprintf(stderr, "HTTP connected, socket %d\n", s);
 255: 
1.17 timbl 256: 
 257: /*   Compose and send command
 258: **   ------------------------
 259: */
 260:   {
 261:     char *command;         /* The whole command */
 262:    
1.1 timbl 263: /*   Ask that node for the document,
 264: **   omitting the host name & anchor if not gatewayed.
 265: */    
1.17 timbl 266:    if (gate) {
 267:      command = malloc(4 + strlen(arg)+ 2 + 31);
 268:      if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
 269:      strcpy(command, "GET ");
 270:      strcat(command, arg);
 271:    } else { /* not gatewayed */
 272:      char * p1 = HTParse(arg, "", PARSE_PATH|PARSE_PUNCTUATION);
 273:      command = malloc(4 + strlen(p1)+ 2 + 31);
 274:      if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
1.23 luotonen 275:      if (request->method != METHOD_INVALID) {
 276:        strcpy(command, HTMethod_name(request->method));
1.22 luotonen 277:        strcat(command, " ");
 278:      }
 279:      else {
 280:        strcpy(command, "GET ");
 281:      }
1.17 timbl 282:      strcat(command, p1);
 283:      free(p1);
 284:    }
1.2 timbl 285: #ifdef HTTP2
1.17 timbl 286:    if (extensions) {
 287:      strcat(command, " ");
 288:      strcat(command, HTTP_VERSION);
 289:    }
1.2 timbl 290: #endif
1.17 timbl 291:   
 292:    strcat(command, crlf); /* CR LF, as in rfc 977 */
 293:   
 294:    if (extensions) {
1.21 luotonen 295: 
1.17 timbl 296:      int i;
 297:      HTAtom * present = WWW_PRESENT;
 298:      char line[256];  /*@@@@ */
1.21 luotonen 299:      HTList *conversions[2];
 300: 
1.22 luotonen 301:      if (!HTConversions) {
 302:        HTConversions = HTList_new();
 303:        HTFormatInit(HTConversions);
 304:      }
1.28 ! timbl 305: 
1.21 luotonen 306:      conversions[0] = HTConversions;
 307:      conversions[1] = request->conversions;
 308: 
 309:      for (i=0; i<2; i++) {
 310:        HTList *cur = conversions[i];
 311:        HTPresentation *pres;
 312: 
 313:        while ((pres = (HTPresentation*)HTList_nextObject(cur))) {
 314:          if (pres->rep_out == present) {
 315:            if (pres->quality != 1.0) {
 316:              sprintf(line, "Accept: %s q=%.3f%c%c",
 317:                  HTAtom_name(pres->rep),
 318:                  pres->quality, CR, LF);
 319:            } else {
 320:              sprintf(line, "Accept: %s%c%c",
 321:                  HTAtom_name(pres->rep), CR, LF);
 322:            }
 323:            StrAllocCat(command, line);
1.17 timbl 324:          }
 325:        }
1.2 timbl 326:      }
1.22 luotonen 327: 
 328:      sprintf(line, "User-Agent: %s%s %s/%s libwww/%s%c%c",
 329:          request->user_agent ? request->user_agent : "",
 330:          request->user_agent ? " VIA Gateway" : "",
1.17 timbl 331:          HTAppName ? HTAppName : "unknown",
 332:          HTAppVersion ? HTAppVersion : "0.0",
 333:          HTLibraryVersion, CR, LF);
 334:          StrAllocCat(command, line);
 335:   
1.22 luotonen 336:      if (request->from) {
 337:        sprintf(line, "From: %s%c%c", request->from, CR, LF);
 338:        StrAllocCat(command, line);
 339:      }
 340: 
1.14 luotonen 341: #ifdef ACCESS_AUTH
1.21 luotonen 342:      if (request->authorization != NULL) {
 343:        sprintf(line, "Authorization: %s%c%c",
 344:            request->authorization, CR, LF);
1.17 timbl 345:        StrAllocCat(command, line);
 346:      }
 347: #endif /* ACCESS_AUTH */
1.22 luotonen 348: 
 349:      if (request->content_type) {
 350:        sprintf(line, "Content-Type: %s%c%c",
 351:            HTAtom_name(request->content_type), CR, LF);
 352:        StrAllocCat(command, line);
 353:      }
 354: 
 355:      if (request->content_length > 0) {
 356:        sprintf(line, "Content-Length: %d%c%c",
 357:            request->content_length, CR, LF);
 358:        StrAllocCat(command, line);
 359:      }
 360: 
 361: 
1.14 luotonen 362:    }
1.17 timbl 363:   
 364:    StrAllocCat(command, crlf);   /* Blank line means "end" */
 365:   
 366:    if (TRACE) fprintf(stderr, "HTTP Tx: %s\n", command);
 367:   
 368:   /* Translate into ASCII if necessary
 369:   */
1.4 timbl 370: #ifdef NOT_ASCII
1.17 timbl 371:    {
 372:      char * p;
 373:      for(p = command; *p; p++) {
 374:        *p = TOASCII(*p);
 375:      }
1.1 timbl 376:    }
1.3 timbl 377: #endif
1.17 timbl 378:   
 379:    status = NETWRITE(s, command, (int)strlen(command));
 380:    free(command);
 381:    if (status<0) {
 382:      if (TRACE) fprintf(stderr,
 383:        "HTTPAccess: Unable to send command.\n");
1.1 timbl 384:      return HTInetStatus("send");
1.17 timbl 385:    }
 386:   } /* compose and send command */
 387:   
1.2 timbl 388: 
1.17 timbl 389: /*   Read the response
 390: **   -----------------
1.11 timbl 391: **
 392: **   HTTP0 servers must return ASCII style text, though it can in
 393: **   principle be just text without any markup at all.
 394: **   Full HTTP servers must return a response
 395: **   line and RFC822 style header. The response must therefore in
 396: **   either case have a CRLF somewhere soon.
 397: **
 398: **   This is the theory. In practice, there are (1993) unfortunately
 399: **   many binary documents just served up with HTTP0.9. This
 400: **   means we have to preserve the binary buffer (on the assumption that
 401: **   conversion from ASCII may lose information) in case it turns
 402: **   out that we want the binary original.
1.2 timbl 403: */
1.3 timbl 404: 
1.22 luotonen 405:   if (request->reason == HTAA_OK_GATEWAY) {
1.24 luotonen 406: 
1.22 luotonen 407:    /*
 408:    ** Server as a gateway -- send body of the message
 409:    ** received from client (if any).
 410:    */
 411:    if (request->isoc && request->content_length > 0) {
 412:      int remain = request->content_length;
 413:      int i = remain;
 414:      char * buf;
 415: 
 416:      while (remain > 0 &&
 417:          (buf = HTInputSocket_getBlock(request->isoc, &i))) {
 418:        int status = NETWRITE(s, buf, i);
 419:        if (status < 0) {
1.27 luotonen 420:          CTRACE(stderr, "HTTPAccess.. Unable to forward body\n");
1.22 luotonen 421:          return HTInetStatus("send");
 422:        }
 423:        remain -= i;
 424:        i = remain;
 425:      }
 426:    }
1.23 luotonen 427: 
 428:    /*
 429:    ** Cache the document if it a GET request,
 430:    ** not protected and not a search request.
 431:    */
1.27 luotonen 432:    if (cache_file_name) {
 433:      FILE * cache_file = fopen(cache_file_name, "w");
1.23 luotonen 434: 
1.27 luotonen 435:      if (cache_file) {
 436:        request->output_stream = HTTee(request->output_stream,
 437:                        HTFWriter_new(cache_file));
 438:        CTRACE(stderr, "Gateway..... writing to cache file\n");
 439:      }
 440:      else {
 441:        HTCacheCancel(arg);
 442:        free(cache_file_name);
 443:        cache_file_name = NULL;
 444:        CTRACE(stderr, "Gateway..... couldn't create cache file\n");
1.23 luotonen 445:      }
 446:    }
1.27 luotonen 447:    else CTRACE(stderr, "Gateway..... not caching\n");
1.23 luotonen 448: 
1.22 luotonen 449:    /*
 450:    ** Load results directly to client
 451:    */
 452:    HTCopy(s, request->output_stream);
1.25 luotonen 453:    (*request->output_stream->isa->free)(request->output_stream);
1.27 luotonen 454:    if (cache_file_name) {
 455:      HTCacheCreated(arg, (time_t)0);
 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.17 timbl 609:    if (format_in == WWW_HTML) {
 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 によって変換されたページ (->オリジナル) /