~ubuntu-branches/ubuntu/lucid/curl/lucid-201101212007

« back to all changes in this revision

Viewing changes to tests/server/sws.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2008-02-08 11:20:41 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: james.westby@ubuntu.com-20080208112041-hed7sb5r6ghmjf8v
Tags: upstream-7.18.0
ImportĀ upstreamĀ versionĀ 7.18.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
 * KIND, either express or implied.
20
20
 *
21
 
 * $Id: sws.c,v 1.108 2007-10-26 00:36:36 yangtse Exp $
 
21
 * $Id: sws.c,v 1.110 2008-01-25 05:08:53 yangtse Exp $
22
22
 ***************************************************************************/
23
23
 
24
24
/* sws.c: simple (silly?) web server
107
107
  int pipe;       /* if non-zero, expect this many requests to do a "piped"
108
108
                     request/response */
109
109
  int rcmd;       /* doing a special command, see defines above */
 
110
  int prot_version; /* HTTP version * 10 */
 
111
  bool pipelining; /* true if request is pipelined */
110
112
};
111
113
 
112
114
int ProcessRequest(struct httprequest *req);
215
217
            &prot_minor) == 4) {
216
218
    char *ptr;
217
219
 
 
220
    req->prot_version = prot_major*10 + prot_minor;
 
221
 
218
222
    /* find the last slash */
219
223
    ptr = strrchr(doc, '/');
220
224
 
315
319
                doc, prot_major, prot_minor);
316
320
        logmsg("%s", logbuf);
317
321
 
318
 
        if(prot_major*10+prot_minor == 10)
 
322
        if(req->prot_version == 10)
319
323
          req->open = FALSE; /* HTTP 1.0 closes connection by default */
320
324
 
321
325
        if(!strncmp(doc, "bad", 3))
427
431
  if(strstr(req->reqbuf, "Connection: close"))
428
432
    req->open = FALSE; /* close connection after this request */
429
433
 
 
434
  if(!req->pipe &&
 
435
     req->open &&
 
436
     req->prot_version >= 11 &&
 
437
     end &&
 
438
     req->reqbuf + req->offset > end + strlen(END_OF_HEADERS) &&
 
439
     (!strncmp(req->reqbuf, "GET", strlen("GET")) ||
 
440
      !strncmp(req->reqbuf, "HEAD", strlen("HEAD")))) {
 
441
    /* If we have a persistent connection, HTTP version >= 1.1
 
442
       and GET/HEAD request, enable pipelining. */
 
443
    req->checkindex = (end - req->reqbuf) + strlen(END_OF_HEADERS);
 
444
    req->pipelining = TRUE;
 
445
  }
 
446
 
430
447
  while(req->pipe) {
431
448
    /* scan for more header ends within this chunk */
432
449
    line = &req->reqbuf[req->checkindex];
512
529
  int fail= FALSE;
513
530
  char *reqbuf = req->reqbuf;
514
531
 
 
532
  char pipereq[REQBUFSIZ];
 
533
  int pipereq_length;
 
534
  if(req->pipelining) {
 
535
    pipereq_length = req->offset - req->checkindex;
 
536
    memcpy(pipereq, reqbuf + req->checkindex, pipereq_length);
 
537
  }
 
538
  else
 
539
    pipereq_length = 0;
 
540
 
515
541
  /*** Init the httpreqest structure properly for the upcoming request ***/
516
542
  memset(req, 0, sizeof(struct httprequest));
517
543
 
524
550
  /*** end of httprequest init ***/
525
551
 
526
552
  while (req->offset < REQBUFSIZ) {
527
 
    ssize_t got = sread(sock, reqbuf + req->offset, REQBUFSIZ - req->offset);
 
553
    ssize_t got;
 
554
    if(pipereq_length) {
 
555
      memcpy(reqbuf, pipereq, pipereq_length);
 
556
      got = pipereq_length;
 
557
      pipereq_length = 0;
 
558
    }
 
559
    else
 
560
      got = sread(sock, reqbuf + req->offset, REQBUFSIZ - req->offset);
528
561
    if (got <= 0) {
529
562
      if (got < 0) {
530
563
        logmsg("recv() returned error: %d", SOCKERRNO);
563
596
    reqbuf[req->offset]=0;
564
597
 
565
598
  /* dump the request to an external file */
566
 
  storerequest(reqbuf, req->offset);
 
599
  storerequest(reqbuf, req->pipelining ? req->checkindex : req->offset);
567
600
 
568
601
  return fail; /* success */
569
602
}
968
1001
    }
969
1002
#endif
970
1003
 
 
1004
  /* full initialization for new request after connection */
 
1005
  memset(&req, 0, sizeof(req));
 
1006
  req.testno = DOCNUMBER_NOTHING;
 
1007
  req.open = TRUE;
 
1008
  req.auth_req = FALSE;
 
1009
  req.auth = FALSE;
 
1010
  req.digest = FALSE;
 
1011
  req.ntlm = FALSE;
 
1012
  req.pipelining = FALSE;
 
1013
 
971
1014
  do {
972
1015
      if(get_request(msgsock, &req))
973
1016
        /* non-zero means error, break out of loop */