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

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

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.29 luotonen 167: #ifdef NOT_USED_YET
1.27 luotonen 168:    if (request->method == METHOD_GET &&
 169:      !request->authorization &&
 170:      !request->arg_keywords) {
1.23 luotonen 171: 
1.27 luotonen 172:      if (HTCacheLookupOrCreate(arg, &cache_file_name)) {
1.23 luotonen 173: 
1.27 luotonen 174:        FILE * cache_file = fopen(cache_file_name, "r");
1.23 luotonen 175: 
1.27 luotonen 176:        if (cache_file) {
 177:          HTFileCopy(cache_file, request->output_stream);
 178:          fclose(cache_file);
 179:          free(cache_file_name);
 180:          (*request->output_stream->isa->free)(request->output_stream);
 181:          return HT_LOADED;
 182:        }
 183:        free(cache_file_name);
 184:        cache_file_name = NULL;
 185:      } /* Cache lookup */
 186:    } /* Can use cache? */
1.29 luotonen 187: #endif /* NOT_USED_YET */
1.27 luotonen 188:   } /* I'm a gateway */
1.22 luotonen 189:   else {
 190:    arg = HTAnchor_physical(request->anchor);
 191:    StrAllocCopy(request->argument, arg);
 192:   }
 193: 
1.1 timbl 194:   if (!arg) return -3;        /* Bad if no name sepcified   */
 195:   if (!*arg) return -2;       /* Bad if name had zero length */
 196: 
 197: /* Set up defaults:
 198: */
 199: #ifdef DECNET
1.2 timbl 200:   sin->sdn_family = AF_DECnet;      /* Family = DECnet, host order */
 201:   sin->sdn_objnum = DNP_OBJ;     /* Default: http object number */
1.1 timbl 202: #else /* Internet */
1.2 timbl 203:   sin->sin_family = AF_INET;   /* Family = internet, host order */
 204:   sin->sin_port = htons(TCP_PORT);  /* Default: http port  */
1.1 timbl 205: #endif
 206: 
1.10 timbl 207:   sprintf(crlf, "%c%c", CR, LF);   /* To be corect on Mac, VM, etc */
 208:   
1.1 timbl 209:   if (TRACE) {
 210:     if (gate) fprintf(stderr,
 211:        "HTTPAccess: Using gateway %s for %s\n", gate, arg);
 212:     else fprintf(stderr, "HTTPAccess: Direct access for %s\n", arg);
 213:   }
 214:   
 215: /* Get node name and optional port number:
 216: */
 217:   {
 218:    char *p1 = HTParse(gate ? gate : arg, "", PARSE_HOST);
 219:    int status = HTParseInet(sin, p1); /* TBL 920622 */
 220:     free(p1);
 221:    if (status) return status;  /* No such host for example */
 222:   }
 223:   
1.15 luotonen 224: /*
 225: ** Compose authorization information (this was moved here
 226: ** from after the making of the connection so that the connection
 227: ** wouldn't have to wait while prompting username and password
 228: ** from the user).               -- AL 13.10.93
 229: */
 230: #ifdef ACCESS_AUTH
1.21 luotonen 231:   HTAA_composeAuth(request);
 232:   if (TRACE) {
 233:    if (request->authorization)
 234:      fprintf(stderr, "HTTP: Sending Authorization: %s\n",
 235:          request->authorization);
 236:    else
 237:      fprintf(stderr, "HTTP: Not sending authorization (yet)\n");
1.15 luotonen 238:   }
 239: #endif /* ACCESS_AUTH */
1.1 timbl 240:  
1.10 timbl 241: /*   Now, let's get a socket set up from the server for the data:
1.1 timbl 242: */   
 243: #ifdef DECNET
 244:   s = socket(AF_DECnet, SOCK_STREAM, 0);
 245: #else
 246:   s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 247: #endif
 248:   status = connect(s, (struct sockaddr*)&soc_address, sizeof(soc_address));
 249:   if (status < 0) {
 250:      if (TRACE) fprintf(stderr, 
1.30 ! frystyk 251:       "HTTP: Unable to connect to remote host for `%s' (errno = %d).\n",
 ! 252:       arg, errno);
1.17 timbl 253: 
1.1 timbl 254:      return HTInetStatus("connect");
 255:    }
 256:   
 257:   if (TRACE) fprintf(stderr, "HTTP connected, socket %d\n", s);
 258: 
1.17 timbl 259: 
 260: /*   Compose and send command
 261: **   ------------------------
 262: */
 263:   {
 264:     char *command;         /* The whole command */
 265:    
1.1 timbl 266: /*   Ask that node for the document,
 267: **   omitting the host name & anchor if not gatewayed.
 268: */    
1.17 timbl 269:    if (gate) {
 270:      command = malloc(4 + strlen(arg)+ 2 + 31);
 271:      if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
 272:      strcpy(command, "GET ");
 273:      strcat(command, arg);
 274:    } else { /* not gatewayed */
 275:      char * p1 = HTParse(arg, "", PARSE_PATH|PARSE_PUNCTUATION);
 276:      command = malloc(4 + strlen(p1)+ 2 + 31);
 277:      if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
1.23 luotonen 278:      if (request->method != METHOD_INVALID) {
 279:        strcpy(command, HTMethod_name(request->method));
1.22 luotonen 280:        strcat(command, " ");
 281:      }
 282:      else {
 283:        strcpy(command, "GET ");
 284:      }
1.17 timbl 285:      strcat(command, p1);
 286:      free(p1);
 287:    }
1.2 timbl 288: #ifdef HTTP2
1.17 timbl 289:    if (extensions) {
 290:      strcat(command, " ");
 291:      strcat(command, HTTP_VERSION);
 292:    }
1.2 timbl 293: #endif
1.17 timbl 294:   
 295:    strcat(command, crlf); /* CR LF, as in rfc 977 */
 296:   
 297:    if (extensions) {
1.21 luotonen 298: 
1.17 timbl 299:      int i;
 300:      HTAtom * present = WWW_PRESENT;
 301:      char line[256];  /*@@@@ */
1.21 luotonen 302:      HTList *conversions[2];
 303: 
1.22 luotonen 304:      if (!HTConversions) {
 305:        HTConversions = HTList_new();
 306:        HTFormatInit(HTConversions);
 307:      }
1.28 timbl 308: 
1.21 luotonen 309:      conversions[0] = HTConversions;
 310:      conversions[1] = request->conversions;
 311: 
 312:      for (i=0; i<2; i++) {
 313:        HTList *cur = conversions[i];
 314:        HTPresentation *pres;
 315: 
 316:        while ((pres = (HTPresentation*)HTList_nextObject(cur))) {
 317:          if (pres->rep_out == present) {
 318:            if (pres->quality != 1.0) {
 319:              sprintf(line, "Accept: %s q=%.3f%c%c",
 320:                  HTAtom_name(pres->rep),
 321:                  pres->quality, CR, LF);
 322:            } else {
 323:              sprintf(line, "Accept: %s%c%c",
 324:                  HTAtom_name(pres->rep), CR, LF);
 325:            }
 326:            StrAllocCat(command, line);
1.17 timbl 327:          }
 328:        }
1.2 timbl 329:      }
1.22 luotonen 330: 
 331:      sprintf(line, "User-Agent: %s%s %s/%s libwww/%s%c%c",
 332:          request->user_agent ? request->user_agent : "",
 333:          request->user_agent ? " VIA Gateway" : "",
1.17 timbl 334:          HTAppName ? HTAppName : "unknown",
 335:          HTAppVersion ? HTAppVersion : "0.0",
 336:          HTLibraryVersion, CR, LF);
 337:          StrAllocCat(command, line);
 338:   
1.22 luotonen 339:      if (request->from) {
 340:        sprintf(line, "From: %s%c%c", request->from, CR, LF);
 341:        StrAllocCat(command, line);
 342:      }
 343: 
1.14 luotonen 344: #ifdef ACCESS_AUTH
1.21 luotonen 345:      if (request->authorization != NULL) {
 346:        sprintf(line, "Authorization: %s%c%c",
 347:            request->authorization, CR, LF);
1.17 timbl 348:        StrAllocCat(command, line);
 349:      }
 350: #endif /* ACCESS_AUTH */
1.22 luotonen 351: 
 352:      if (request->content_type) {
 353:        sprintf(line, "Content-Type: %s%c%c",
 354:            HTAtom_name(request->content_type), CR, LF);
 355:        StrAllocCat(command, line);
 356:      }
 357: 
 358:      if (request->content_length > 0) {
 359:        sprintf(line, "Content-Length: %d%c%c",
 360:            request->content_length, CR, LF);
 361:        StrAllocCat(command, line);
 362:      }
 363: 
 364: 
1.14 luotonen 365:    }
1.17 timbl 366:   
 367:    StrAllocCat(command, crlf);   /* Blank line means "end" */
 368:   
 369:    if (TRACE) fprintf(stderr, "HTTP Tx: %s\n", command);
 370:   
 371:   /* Translate into ASCII if necessary
 372:   */
1.4 timbl 373: #ifdef NOT_ASCII
1.17 timbl 374:    {
 375:      char * p;
 376:      for(p = command; *p; p++) {
 377:        *p = TOASCII(*p);
 378:      }
1.1 timbl 379:    }
1.3 timbl 380: #endif
1.17 timbl 381:   
 382:    status = NETWRITE(s, command, (int)strlen(command));
 383:    free(command);
 384:    if (status<0) {
 385:      if (TRACE) fprintf(stderr,
 386:        "HTTPAccess: Unable to send command.\n");
1.1 timbl 387:      return HTInetStatus("send");
1.17 timbl 388:    }
 389:   } /* compose and send command */
 390:   
1.2 timbl 391: 
1.17 timbl 392: /*   Read the response
 393: **   -----------------
1.11 timbl 394: **
 395: **   HTTP0 servers must return ASCII style text, though it can in
 396: **   principle be just text without any markup at all.
 397: **   Full HTTP servers must return a response
 398: **   line and RFC822 style header. The response must therefore in
 399: **   either case have a CRLF somewhere soon.
 400: **
 401: **   This is the theory. In practice, there are (1993) unfortunately
 402: **   many binary documents just served up with HTTP0.9. This
 403: **   means we have to preserve the binary buffer (on the assumption that
 404: **   conversion from ASCII may lose information) in case it turns
 405: **   out that we want the binary original.
1.2 timbl 406: */
1.3 timbl 407: 
1.22 luotonen 408:   if (request->reason == HTAA_OK_GATEWAY) {
1.24 luotonen 409: 
1.22 luotonen 410:    /*
 411:    ** Server as a gateway -- send body of the message
 412:    ** received from client (if any).
 413:    */
 414:    if (request->isoc && request->content_length > 0) {
 415:      int remain = request->content_length;
 416:      int i = remain;
 417:      char * buf;
 418: 
 419:      while (remain > 0 &&
 420:          (buf = HTInputSocket_getBlock(request->isoc, &i))) {
 421:        int status = NETWRITE(s, buf, i);
 422:        if (status < 0) {
1.27 luotonen 423:          CTRACE(stderr, "HTTPAccess.. Unable to forward body\n");
1.22 luotonen 424:          return HTInetStatus("send");
 425:        }
 426:        remain -= i;
 427:        i = remain;
 428:      }
 429:    }
1.23 luotonen 430: 
 431:    /*
 432:    ** Cache the document if it a GET request,
 433:    ** not protected and not a search request.
 434:    */
1.27 luotonen 435:    if (cache_file_name) {
 436:      FILE * cache_file = fopen(cache_file_name, "w");
1.23 luotonen 437: 
1.27 luotonen 438:      if (cache_file) {
 439:        request->output_stream = HTTee(request->output_stream,
 440:                        HTFWriter_new(cache_file));
 441:        CTRACE(stderr, "Gateway..... writing to cache file\n");
 442:      }
 443:      else {
1.29 luotonen 444: #ifdef NOT_USED_YET
1.27 luotonen 445:        HTCacheCancel(arg);
1.29 luotonen 446: #endif /* NOT_USED_YET */
1.27 luotonen 447:        free(cache_file_name);
 448:        cache_file_name = NULL;
 449:        CTRACE(stderr, "Gateway..... couldn't create cache file\n");
1.23 luotonen 450:      }
 451:    }
1.27 luotonen 452:    else CTRACE(stderr, "Gateway..... not caching\n");
1.23 luotonen 453: 
1.22 luotonen 454:    /*
 455:    ** Load results directly to client
 456:    */
 457:    HTCopy(s, request->output_stream);
1.25 luotonen 458:    (*request->output_stream->isa->free)(request->output_stream);
1.27 luotonen 459:    if (cache_file_name) {
1.29 luotonen 460: #ifdef NOT_USED_YET
1.27 luotonen 461:      HTCacheCreated(arg, (time_t)0);
1.29 luotonen 462: #endif /* NOT_USED_YET */
1.27 luotonen 463:      free(cache_file_name);
1.24 luotonen 464:    }
1.22 luotonen 465:    return HT_LOADED;
 466:   }
 467:   else {   /* read response */
1.21 luotonen 468: 
1.17 timbl 469:    HTFormat format_in;       /* Format arriving in the message */
1.21 luotonen 470:    HTInputSocket *isoc = HTInputSocket_new(s);
 471:    char * status_line = HTInputSocket_getStatusLine(isoc);
1.2 timbl 472: 
1.11 timbl 473: /* Kludge to trap binary responses from illegal HTTP0.9 servers.
 474: ** First time we have enough, look at the stub in ASCII
 475: ** and get out of here if it doesn't look right.
 476: **
 477: ** We also check for characters above 128 in the first few bytes, and
 478: ** if we find them we forget the html default.
 479: **
 480: ** Bugs: A HTTP0.9 server returning a document starting "HTTP/"
 481: **   will be taken as a HTTP 1.0 server. Failure.
 482: **   An HTTP 0.9 server returning a binary document with
 483: **   characters < 128 will be read as ASCII.
 484: */
1.21 luotonen 485:    if (!status_line) {   /* HTTP0 response */
 486:      if (HTInputSocket_seemsBinary(isoc)) {
 487:        format_in = HTAtom_for("www/unknown");
 488:      }
 489:      else {
 490:        format_in = WWW_HTML;
 491:      }
 492:      goto copy;
 493:    } /* end kludge */
 494: 
 495:    if (status_line) {   /* Decode full HTTP response */
 496:      /*
 497:      ** We now have a terminated server status line, and we have
 498:      ** checked that it is most probably a legal one. Parse it.
 499:      */
 500:      char server_version[VERSION_LENGTH+1];
 501:      int server_status;
 502: 
 503:      if (TRACE)
 504:        fprintf(stderr, "HTTP Status Line: Rx: %.70s\n", status_line);
1.17 timbl 505:   
1.21 luotonen 506:      sscanf(status_line, "%20s%d", server_version, &server_status);
1.2 timbl 507: 
1.21 luotonen 508:      format_in = HTAtom_for("www/mime");
1.7 timbl 509:   
1.21 luotonen 510:      switch (server_status / 100) {
1.2 timbl 511: 
1.21 luotonen 512:       default:     /* bad number */
 513:        HTAlert("Unknown status reply from server!");
 514:        break;
1.17 timbl 515:          
1.21 luotonen 516:       case 3:      /* Various forms of redirection */
 517:        HTAlert(
1.17 timbl 518:      "Redirection response from server is not handled by this client");
1.21 luotonen 519:        break;
1.17 timbl 520:          
1.21 luotonen 521:       case 4:      /* Access Authorization problem */
1.14 luotonen 522: #ifdef ACCESS_AUTH
1.21 luotonen 523:        switch (server_status) {
 524:         case 401:
 525:          parse_401_headers(request, isoc);
 526: 
 527:          if (TRACE) fprintf(stderr, "%s %d %s\n",
 528:                    "HTTP: close socket", s,
 529:                    "to retry with Access Authorization");
 530:          HTInputSocket_free(isoc);
 531:          (void)NETCLOSE(s);
1.24 luotonen 532:          if (HTAA_retryWithAuth(request, HTLoadHTTP)) {
1.21 luotonen 533:            status = HT_LOADED;/* @@ THIS ONLY WORKS ON LINEMODE */
 534:            goto clean_up;
 535:          }
 536:          /* else falltrough */
 537:         default:
1.14 luotonen 538:          {
1.21 luotonen 539:            char *p1 = HTParse(gate ? gate : arg, "",
 540:                      PARSE_HOST);
 541:            char * message;
 542: 
 543:            if (!(message = (char*)malloc(strlen(status_line) +
 544:                           strlen(p1) + 100)))
 545:              outofmem(__FILE__, "HTTP 4xx status");
1.14 luotonen 546:            sprintf(message,
1.21 luotonen 547:                "HTTP server at %s replies:\n%s\n\n%s\n",
 548:                p1, status_line,
 549:                ((server_status == 401) 
 550:                 ? "Access Authorization package giving up.\n"
 551:                 : ""));
1.22 luotonen 552:            status = HTLoadError(request, server_status, message);
1.14 luotonen 553:            free(message);
 554:            free(p1);
 555:            goto clean_up;
 556:          }
1.21 luotonen 557:        } /* switch */
 558:        goto clean_up;
 559:        break;
 560: #else
 561:        /* case 4 without Access Authorization falls through */
 562:        /* to case 5 (previously "I think I goofed"). -- AL */
 563: #endif /* ACCESS_AUTH */
 564: 
 565:       case 5:      /* I think you goofed */
 566:        {
 567:          char *p1 = HTParse(gate ? gate : arg, "", PARSE_HOST);
 568:          char * message = (char*)malloc(strlen(status_line) + 
 569:                          strlen(p1) + 100);
 570:          if (!message) outofmem(__FILE__, "HTTP 5xx status");
 571:          sprintf(message,
 572:              "HTTP server at %s replies:\n%s", p1, status_line);
1.22 luotonen 573:          status = HTLoadError(request, server_status, message);
1.21 luotonen 574:          free(message);
 575:          free(p1);
 576:          goto clean_up;
 577:        }
 578:        break;
1.17 timbl 579:          
1.21 luotonen 580:       case 2:      /* Good: Got MIME object */
 581:        break;
1.17 timbl 582:   
1.21 luotonen 583:      } /* switch on response code */
1.17 timbl 584:      
1.21 luotonen 585:    } /* Full HTTP reply */
1.17 timbl 586:      
 587:   
1.3 timbl 588: /*   Set up the stream stack to handle the body of the message
 589: */
1.21 luotonen 590: 
1.13 duns 591: copy:
1.21 luotonen 592: 
1.18 timbl 593:    target = HTStreamStack(format_in, request);
1.21 luotonen 594: 
1.17 timbl 595:    if (!target) {
 596:      char buffer[1024]; /* @@@@@@@@ */
 597:      sprintf(buffer, "Sorry, no known way of converting %s to %s.",
 598:          HTAtom_name(format_in), HTAtom_name(request->output_format));
 599:      fprintf(stderr, "HTTP: %s", buffer);
1.22 luotonen 600:      status = HTLoadError(request, 501, buffer);
1.17 timbl 601:      goto clean_up;
 602:    }
 603:   
1.19 timbl 604:     /* @@ Bug: The decision of whether or not to cache should also be
1.21 luotonen 605:    ** made contingent on a IP address match or non match.
 606:    */
1.19 timbl 607:     if (HTCacheHTTP) {
 608:      target = HTTee(target, HTCacheWriter(request, NULL, format_in,
1.21 luotonen 609:                         request->output_format,
 610:                         request->output_stream));
1.19 timbl 611:    }
 612:    
1.11 timbl 613: /*   Push the data down the stream
1.3 timbl 614: **   We have to remember the end of the first buffer we just read
1.2 timbl 615: */
1.30 ! frystyk 616:    if (format_in == WWW_HTML) { 
1.17 timbl 617:      target = HTNetToText(target);    /* Pipe through CR stripper */
 618:    }
1.21 luotonen 619: 
1.17 timbl 620:    (*target->isa->put_block)(target,
1.21 luotonen 621:                 isoc->input_pointer,
 622:                 isoc->input_limit - isoc->input_pointer);
 623:    HTInputSocket_free(isoc);
1.17 timbl 624:    HTCopy(s, target);
 625:      
 626:    (*target->isa->free)(target);
 627:    status = HT_LOADED;
1.11 timbl 628:   
1.2 timbl 629: /*   Clean up
1.1 timbl 630: */
1.17 timbl 631:    
 632: clean_up: 
 633:    if (TRACE) fprintf(stderr, "HTTP: close socket %d.\n", s);
 634:    (void) NETCLOSE(s);
 635:   
 636:    return status;         /* Good return */
1.3 timbl 637:   
1.17 timbl 638:   } /* read response */
 639: } /* load HTTP */
1.1 timbl 640: 
 641: /*   Protocol descriptor
 642: */
 643: 
1.17 timbl 644: GLOBALDEF PUBLIC HTProtocol HTTP = { "http", HTLoadHTTP, 0, 0 };
1.21 luotonen 645: 

Webmaster

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