Commit 41dd5121 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

adjusted to work on test case 11 better

parent 94482d7c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#define show(x)
#endif

static
char *appendstring(char *string, /* original string */
                   char *buffer, /* to append */
                   int *stringlen, int *stralloc)
@@ -46,7 +47,6 @@ char *spitout(FILE *stream, char *main, char *sub, int *size)
  char *string;
  int stringlen=0;
  int stralloc=256;
  int len;

  enum {
    STATE_OUTSIDE,
+89 −72
Original line number Diff line number Diff line
@@ -5,14 +5,14 @@
#include <string.h>
#include <unistd.h>
#include <signal.h>
#include <getopt.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <assert.h>

char *spitout(FILE *stream, char *main, char *sub, int *size);

#define DEFAULT_PORT 8999

@@ -80,7 +80,7 @@ static void sigterm_handler(int sig)
int ProcessRequest(char *request)
{
  char *line=request;
  long contentlength=-1;
  unsigned long contentlength=0;

#define END_OF_HEADERS "\r\n\r\n"

@@ -111,7 +111,7 @@ int ProcessRequest(char *request)
      line++;
  } while(line);

  if(contentlength > -1 ) {
  if(contentlength > 0 ) {
    if(contentlength <= strlen(end+strlen(END_OF_HEADERS)))
      return 1; /* done */
    else
@@ -138,13 +138,15 @@ void storerequest(char *reqbuf)
#define REQBUFSIZ 4096
#define MAXDOCNAMELEN 1024
#define REQUEST_KEYWORD_SIZE 256
static int get_request(int sock)
static int get_request(int sock, int *part)
{
  char reqbuf[REQBUFSIZ], doc[MAXDOCNAMELEN];
  char request[REQUEST_KEYWORD_SIZE];
  unsigned int offset = 0;
  int prot_major, prot_minor;

  *part = 0; /* part zero equals none */

  while (offset < REQBUFSIZ) {
    int got = recv(sock, reqbuf + offset, REQBUFSIZ - offset, 0);
    if (got <= 0) {
@@ -191,7 +193,15 @@ static int get_request(int sock)
        logmsg("Are-we-friendly question received");
        return -2;
      }
      test_no = strtol(ptr+1, &ptr, 10);

      ptr++; /* skip the slash */

      test_no = strtol(ptr, &ptr, 10);

      if(test_no > 10000) {
        *part = test_no % 10000;
        test_no /= 10000;
      }

      logmsg("Found test number in PATH");
    }
@@ -209,7 +219,7 @@ static int get_request(int sock)
}


static int send_doc(int sock, int doc)
static int send_doc(int sock, int doc, int part_no)
{
  int written;
  int count;
@@ -218,6 +228,7 @@ static int send_doc(int sock, int doc)
  FILE *stream;

  char filename[256];
  char partbuf[80]="data";

  if(doc < 0) {
    if(-2 == doc)
@@ -237,7 +248,11 @@ static int send_doc(int sock, int doc)
      return 0;
    }

    ptr = buffer = spitout(stream, "reply", "data", &count);
    if(0 != part_no) {
      sprintf(partbuf, "data%d", part_no);
    }

    ptr = buffer = spitout(stream, "reply", partbuf, &count);
  }

  do {
@@ -264,6 +279,7 @@ int main(int argc, char *argv[])
  int sock, msgsock, flag;
  unsigned short port = DEFAULT_PORT;
  char *logfile = DEFAULT_LOGFILE;
  int part_no;
  
  if(argc>1)
    port = atoi(argv[1]);
@@ -276,6 +292,7 @@ int main(int argc, char *argv[])
    exit(1);
  }

  /* FIX: make a more portable signal handler */
  signal(SIGPIPE, sigpipe_handler);
  signal(SIGINT, sigterm_handler);
  signal(SIGTERM, sigterm_handler);
@@ -329,8 +346,8 @@ int main(int argc, char *argv[])
    
    logmsg("New client connected");

      doc = get_request(msgsock);
      send_doc(msgsock, doc);
    doc = get_request(msgsock, &part_no);
    send_doc(msgsock, doc, part_no);

    close(msgsock);
  }