diff options
| author | Daniel Stenberg <daniel@haxx.se> | 2004-11-29 12:10:09 +0000 | 
|---|---|---|
| committer | Daniel Stenberg <daniel@haxx.se> | 2004-11-29 12:10:09 +0000 | 
| commit | 0eb8414750456a7a2584a8863b1e217e8bff88cd (patch) | |
| tree | bd5c9d2ecd88446c8b1ea2f8e14e303fe9718db6 /tests/server | |
| parent | 09717d3fc82a858620026538600c311a851dfe14 (diff) | |
Enable test cases to provide sections base64-encoded to be able to test
with binary data.
Diffstat (limited to 'tests/server')
| -rw-r--r-- | tests/server/Makefile.am | 13 | ||||
| -rw-r--r-- | tests/server/getpart.c | 64 | ||||
| -rw-r--r-- | tests/server/getpart.h | 10 | ||||
| -rw-r--r-- | tests/server/sws.c | 3 | 
4 files changed, 68 insertions, 22 deletions
diff --git a/tests/server/Makefile.am b/tests/server/Makefile.am index a655e3f63..73cd3c2ce 100644 --- a/tests/server/Makefile.am +++ b/tests/server/Makefile.am @@ -29,9 +29,16 @@ AUTOMAKE_OPTIONS = foreign  INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/include -noinst_PROGRAMS = sws +noinst_PROGRAMS = sws getpart -sws_SOURCES= sws.c getpart.c getpart.h $(top_srcdir)/lib/strequal.c +sws_SOURCES= sws.c getpart.c getpart.h $(top_srcdir)/lib/strequal.c	\ + $(top_srcdir)/lib/base64.c $(top_srcdir)/lib/mprintf.c			\ + $(top_srcdir)/lib/memdebug.c -extra_DIST = config.h.in +extra_DIST = base64.pl +getpart_CPPFLAGS = -DGETPART_TEST + +getpart_SOURCES= getpart.c getpart.h $(top_srcdir)/lib/strequal.c	\ + $(top_srcdir)/lib/base64.c $(top_srcdir)/lib/mprintf.c			\ + $(top_srcdir)/lib/memdebug.c diff --git a/tests/server/getpart.c b/tests/server/getpart.c index 9cb919fe1..0ae6c391c 100644 --- a/tests/server/getpart.c +++ b/tests/server/getpart.c @@ -1,8 +1,8 @@  /*************************************************************************** - *                                  _   _ ____  _      - *  Project                     ___| | | |  _ \| |     - *                             / __| | | | |_) | |     - *                            | (__| |_| |  _ <| |___  + *                                  _   _ ____  _ + *  Project                     ___| | | |  _ \| | + *                             / __| | | | |_) | | + *                            | (__| |_| |  _ <| |___   *                             \___|\___/|_| \_\_____|   *   * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. @@ -10,7 +10,7 @@   * This software is licensed as described in the file COPYING, which   * you should have received as part of this distribution. The terms   * are also available at http://curl.haxx.se/docs/copyright.html. - *  + *   * You may opt to use, copy, modify, merge, publish, distribute and/or sell   * copies of the Software, and permit persons to whom the Software is   * furnished to do so, under the terms of the COPYING file. @@ -27,6 +27,14 @@  #include <stdlib.h>  #include "getpart.h" +#define _MPRINTF_REPLACE /* use our functions only */ +#include <curl/mprintf.h> + +#include "base64.h" + +/* include memdebug.h last */ +#include "memdebug.h" +  #define EAT_SPACE(ptr) while( ptr && *ptr && isspace((int)*ptr) ) ptr++  #define EAT_WORD(ptr) while( ptr && *ptr && !isspace((int)*ptr) && ('>' != *ptr)) ptr++ @@ -36,14 +44,29 @@  #define show(x)  #endif +curl_malloc_callback Curl_cmalloc = (curl_malloc_callback)malloc; +curl_free_callback Curl_cfree = (curl_free_callback)free; +curl_realloc_callback Curl_crealloc = (curl_realloc_callback)realloc; +curl_strdup_callback Curl_cstrdup = (curl_strdup_callback)strdup; +curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc; +  static  char *appendstring(char *string, /* original string */                     char *buffer, /* to append */                     size_t *stringlen, /* length of string */ -                   size_t *stralloc)  /* allocated size */ +                   size_t *stralloc,  /* allocated size */ +                   char base64) /* 1 if base64 encoded */  {    size_t len = strlen(buffer);    size_t needed_len = len + *stringlen; +  char buf64[256]; /* big enough? */ + +  if(base64) { +    /* decode the given buffer first */ +    len = Curl_base64_decode(buffer, buf64); /* updated len */ +    buffer = buf64; +    needed_len = len + *stringlen; /* recalculate */ +  }    if(needed_len >= *stralloc) {      char *newptr; @@ -57,7 +80,8 @@ char *appendstring(char *string, /* original string */      else        return NULL;    } -  strcpy(&string[*stringlen], buffer); +  /* memcpy to support binary blobs */ +  memcpy(&string[*stringlen], buffer, len);    *stringlen += len;    return string; @@ -77,6 +101,7 @@ const char *spitout(FILE *stream,    char *string;    size_t stringlen=0;    size_t stralloc=256; +  char base64 = 0; /* set to 1 if true */    enum {      STATE_OUTSIDE, @@ -90,7 +115,7 @@ const char *spitout(FILE *stream,      return NULL;    string[0] = 0; /* zero first byte in case of no data */ -   +    while(fgets(buffer, sizeof(buffer), stream)) {      ptr = buffer; @@ -101,7 +126,7 @@ const char *spitout(FILE *stream,      if('<' != *ptr) {        if(display) {          show(("=> %s", buffer)); -        string = appendstring(string, buffer, &stringlen, &stralloc); +        string = appendstring(string, buffer, &stringlen, &stralloc, base64);          show(("* %s\n", buffer));        }        continue; @@ -138,7 +163,7 @@ const char *spitout(FILE *stream,        /* this is the beginning of a section */        end = ptr;        EAT_WORD(end); -       +        *end = 0;        switch(state) {        case STATE_OUTSIDE: @@ -152,9 +177,19 @@ const char *spitout(FILE *stream,        default:          break;        } + +      if(!end[1] != '>') { +        /* There might be attributes here. Check for those we know of and care +           about. */ +        if(strstr(&end[1], "base64=")) { +          /* rought and dirty, but "mostly" functional */ +          /* Treat all data as base64 encoded */ +          base64 = 1; +        } +      }      }      if(display) { -      string = appendstring(string, buffer, &stringlen, &stralloc); +      string = appendstring(string, buffer, &stringlen, &stralloc, base64);        show(("* %s\n", buffer));      } @@ -174,15 +209,16 @@ const char *spitout(FILE *stream,    return string;  } -#ifdef TEST +#ifdef GETPART_TEST  int main(int argc, char **argv)  {    if(argc< 3) {      printf("./moo main sub\n");    }    else { -    int size; -    char *buffer = spitout(stdin, argv[1], argv[2], &size); +    size_t size; +    const char *buffer = spitout(stdin, argv[1], argv[2], &size); +    printf("%s", buffer);    }    return 0;  } diff --git a/tests/server/getpart.h b/tests/server/getpart.h index f50e122f0..0ded4f73f 100644 --- a/tests/server/getpart.h +++ b/tests/server/getpart.h @@ -1,8 +1,8 @@  /*************************************************************************** - *                                  _   _ ____  _      - *  Project                     ___| | | |  _ \| |     - *                             / __| | | | |_) | |     - *                            | (__| |_| |  _ <| |___  + *                                  _   _ ____  _ + *  Project                     ___| | | |  _ \| | + *                             / __| | | | |_) | | + *                            | (__| |_| |  _ <| |___   *                             \___|\___/|_| \_\_____|   *   * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al. @@ -10,7 +10,7 @@   * This software is licensed as described in the file COPYING, which   * you should have received as part of this distribution. The terms   * are also available at http://curl.haxx.se/docs/copyright.html. - *  + *   * You may opt to use, copy, modify, merge, publish, distribute and/or sell   * copies of the Software, and permit persons to whom the Software is   * furnished to do so, under the terms of the COPYING file. diff --git a/tests/server/sws.c b/tests/server/sws.c index db2979175..a42f7ee90 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -81,6 +81,9 @@  static void win32_cleanup(void);  #endif +/* include memdebug.h last */ +#include "memdebug.h" +  #define REQBUFSIZ 150000  #define REQBUFSIZ_TXT "149999"  | 
