httpd-apreq-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject cvs commit: httpd-apreq-2/t cookie.c Makefile.am env.c tables.c test_apreq.h testall.c
Date Mon, 21 Apr 2003 18:45:59 GMT
joes        2003/04/21 11:45:58

  Modified:    src      apreq_cookie.c
               t        Makefile.am env.c tables.c test_apreq.h testall.c
  Added:       t        cookie.c
  Log:
  Add cookie tests; cookie bugfixes.
  
  Revision  Changes    Path
  1.10      +15 -13    httpd-apreq-2/src/apreq_cookie.c
  
  Index: apreq_cookie.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/src/apreq_cookie.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- apreq_cookie.c	12 Apr 2003 01:45:30 -0000	1.9
  +++ apreq_cookie.c	21 Apr 2003 18:45:57 -0000	1.10
  @@ -392,6 +392,8 @@
               if (status == APR_SUCCESS) {
                   c = apreq_make_cookie(ctx, version, name, nlen, 
                                         value, vlen);
  +                apreq_log(APREQ_DEBUG status, ctx, 
  +                          "adding cookie: %s => %s", c->v.name, c->v.data);
                   apreq_add_cookie(j, c);
               }
               else {
  @@ -405,6 +407,7 @@
       return j;
   }
   
  +
   APREQ_DECLARE(int) apreq_serialize_cookie(char *buf, apr_size_t len,
                                             const apreq_cookie_t *c)
   {
  @@ -424,25 +427,29 @@
       
   #define ADD_ATTR(name) do { strcpy(f,c->name ? "; " #name "=%s" : \
                                       "%.0s"); f+= strlen(f); } while (0)
  +#define NONNULL(attr) (attr ? attr : "")
   
  -    if (c->version == NETSCAPE) {
   
  +    if (c->version == NETSCAPE) {
  +        
           ADD_ATTR(path);
           ADD_ATTR(domain);
   
  -        strcpy(f, c->time.expires ? "; expires=%s" : "%.0s");
  +        strcpy(f, c->time.expires ? "; expires=%s" : "");
           f += strlen(f);
   
           if (c->secure)
               strcpy(f, "; secure");
   
           return apr_snprintf(buf, len, format, c->v.name, c->v.data,
  -                           c->path, c->domain, c->time.expires);
  +            NONNULL(c->path), NONNULL(c->domain), c->time.expires);
       }
   
       /* c->version == RFC */
   
  -    ADD_ATTR(version);
  +    strcpy(f,"; Version=%d");
  +    f += strlen(f);
  +
       ADD_ATTR(path);
       ADD_ATTR(domain);
       ADD_ATTR(port);
  @@ -451,13 +458,7 @@
   
   #undef ADD_ATTR
   
  -    /* "%.0s" very hackish, but it should be safe.  max_age is
  -     * the last va_arg, and we're not actually printing it in 
  -     * the "%.0s" case. Should check the apr_snprintf implementation
  -     * just for certainty though.
  -     */
  -
  -    strcpy(f, c->time.max_age >= 0 ? "; max-age=%ld" : "%.0s");
  +    strcpy(f, c->time.max_age >= 0 ? "; max-age=%ld" : "");
   
       f += strlen(f);
   
  @@ -465,8 +466,9 @@
           strcpy(f, "; secure");
   
       return apr_snprintf(buf, len, format, c->v.name, c->v.data,
  -                        c->version, c->path, c->domain, c->port,
  -                        c->comment, c->commentURL, c->time.max_age);
  +                        c->version, NONNULL(c->path), NONNULL(c->domain), 
  +                        NONNULL(c->port), NONNULL(c->comment), 
  +                        NONNULL(c->commentURL), c->time.max_age);
   }
   
   
  
  
  
  1.4       +1 -1      httpd-apreq-2/t/Makefile.am
  
  Index: Makefile.am
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/Makefile.am,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Makefile.am	19 Apr 2003 09:42:08 -0000	1.3
  +++ Makefile.am	21 Apr 2003 18:45:57 -0000	1.4
  @@ -2,7 +2,7 @@
   LIBS = -L../src
   
   noinst_LIBRARIES = libapreq_tests.a
  -libapreq_tests_a_SOURCES = CuTest.c env.c tables.c
  +libapreq_tests_a_SOURCES = CuTest.c env.c tables.c cookie.c
   libapreq_tests_a_LIBADD = ../src/libapreq.la
   
   check_PROGRAMS = testall
  
  
  
  1.4       +17 -5     httpd-apreq-2/t/env.c
  
  Index: env.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/env.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- env.c	21 Apr 2003 04:29:47 -0000	1.3
  +++ env.c	21 Apr 2003 18:45:57 -0000	1.4
  @@ -60,9 +60,8 @@
   
   #include "apr_lib.h"
   #include "apr_strings.h"
  -
   #include <stdlib.h>
  -#include <stdio.h>
  +#include "test_apreq.h"
   
   #define dENV struct env_ctx *env = (struct env_ctx *)ctx
   
  @@ -80,8 +79,7 @@
   
   static apr_pool_t *env_pool(void *ctx)
   {
  -    dENV;
  -    return env->pool;
  +    return p;
   }
   
   static const char *env_in(void *ctx, const char *name)
  @@ -128,6 +126,20 @@
       return NULL;
   }
   
  +static int loglevel = 10;
  +APREQ_LOG(env_log)
  +{
  +    va_list vp;
  +
  +    if (level < loglevel)
  +        return;
  +
  +    va_start(vp, fmt);
  +    fprintf(stderr, "[%s(%d)] %s\n", file, line, apr_pvsprintf(p,fmt,vp));
  +    va_end(vp);
  +    
  +}
  +
   
   static int dump_table(void *ctx, const char *key, const char *value)
   {
  @@ -148,6 +160,6 @@
       env_jar,
       env_request,
       env_cfg,
  -    NULL
  +    env_log
    };
   
  
  
  
  1.6       +20 -3     httpd-apreq-2/t/tables.c
  
  Index: tables.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/tables.c,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- tables.c	21 Apr 2003 16:09:10 -0000	1.5
  +++ tables.c	21 Apr 2003 18:45:57 -0000	1.6
  @@ -110,10 +110,27 @@
   {
       const char *val;
   
  -    apreq_table_add(t1, V("addkey", "bar"));
  -    apreq_table_add(t1, V("addkey", "foo"));
  -     val = apreq_table_get(t1, "addkey");
  +    apreq_table_add(t1, V("add", "bar"));
  +    apreq_table_add(t1, V("add", "foo"));
  +    val = apreq_table_get(t1, "add");
       CuAssertStrEquals(tc, "bar", val);
  +    apreq_table_add(t1, V("fl", "left"));
  +    apreq_table_add(t1, V("fr", "right"));
  +    apreq_table_add(t1, V("fll", "left-left"));
  +    apreq_table_add(t1, V("frr", "right-right"));
  +    apreq_table_add(t1, V("frl", "right-left"));
  +    apreq_table_add(t1, V("flr", "left-right"));
  +    apreq_table_add(t1, V("b", "bah"));
  +    val = apreq_table_get(t1, "foo");
  +    CuAssertStrEquals(tc, "bar", val);
  +    val = apreq_table_get(t1, "fl");
  +    CuAssertStrEquals(tc, "left", val);
  +    val = apreq_table_get(t1, "fr");
  +    CuAssertStrEquals(tc, "right", val);
  +    val = apreq_table_get(t1, "fll");
  +    CuAssertStrEquals(tc, "left-left", val);
  +    val = apreq_table_get(t1, "frl");
  +    CuAssertStrEquals(tc, "right-left", val);
   
   }
   
  
  
  
  1.2       +1 -28     httpd-apreq-2/t/test_apreq.h
  
  Index: test_apreq.h
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/test_apreq.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- test_apreq.h	19 Apr 2003 16:21:31 -0000	1.1
  +++ test_apreq.h	21 Apr 2003 18:45:57 -0000	1.2
  @@ -66,35 +66,8 @@
   
   CuSuite *getsuite(void);
   
  -CuSuite *teststr(void);
  -CuSuite *testtime(void);
  -CuSuite *testvsn(void);
  -CuSuite *testipsub(void);
  -CuSuite *testmmap(void);
  -CuSuite *testud(void);
   CuSuite *testtable(void);
  -CuSuite *testhash(void);
  -CuSuite *testsleep(void);
  -CuSuite *testpool(void);
  -CuSuite *testfmt(void);
  -CuSuite *testfile(void);
  -CuSuite *testdir(void);
  -CuSuite *testfileinfo(void);
  -CuSuite *testrand(void);
  -CuSuite *testdso(void);
  -CuSuite *testoc(void);
  -CuSuite *testdup(void);
  -CuSuite *testsockets(void);
  -CuSuite *testproc(void);
  -CuSuite *testpoll(void);
  -CuSuite *testlock(void);
  -CuSuite *testsockopt(void);
  -CuSuite *testpipe(void);
  -CuSuite *testthread(void);
  -CuSuite *testgetopt(void);
  -CuSuite *testnames(void);
  -CuSuite *testuser(void);
  -CuSuite *testpath(void);
  +CuSuite *testcookie(void);
   CuSuite *testenv(void);
   
   /* Assert that RV is an APR_SUCCESS value; else fail giving strerror
  
  
  
  1.4       +1 -29     httpd-apreq-2/t/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/httpd-apreq-2/t/testall.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- testall.c	19 Apr 2003 16:21:31 -0000	1.3
  +++ testall.c	21 Apr 2003 18:45:57 -0000	1.4
  @@ -78,36 +78,8 @@
       const char *testname;
       CuSuite *(*func)(void);
   } tests[] = {
  -/*    {"teststr", teststr},
  -    {"testtime", testtime},
  -    {"testvsn", testvsn},
  -    {"testipsub", testipsub},
  -    {"testmmap", testmmap},
  -    {"testud", testud}, */
       {"tables", testtable},
  -/*    {"testhash", testhash},
  -    {"testsleep", testsleep},
  -    {"testpool", testpool},
  -    {"testfmt", testfmt},
  -    {"testfile", testfile},
  -    {"testfileinfo", testfileinfo},
  -    {"testpipe", testpipe},
  -    {"testdup", testdup},
  -    {"testdir", testdir},
  -    {"testrand", testrand},
  -    {"testdso", testdso},
  -    {"testoc", testoc},
  -    {"testsockets", testsockets},
  -    {"testsockopt", testsockopt},
  -    {"testproc", testproc},
  -    {"testpoll", testpoll},
  -    {"testlock", testlock},
  -    {"testthread", testthread},
  -    {"testargs", testgetopt},
  -    {"testnames", testnames},
  -    {"testuser", testuser},
  -    {"testpath", testpath},
  -    {"testenv", testenv}, */
  +    {"cookies", testcookie},
       {"LastTest", NULL}
   };
   
  
  
  
  1.1                  httpd-apreq-2/t/cookie.c
  
  Index: cookie.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  #include "apreq_env.h"
  #include "test_apreq.h"
  #include "apreq.h"
  #include "apreq_cookie.h"
  #include "apr_strings.h"
  
  static apreq_jar_t *j = NULL;
  
  static void jar_make(CuTest *tc)
  {
      j = apreq_jar(p,"a=1; foo=bar; fl=left; fr=right; frl=right-left; flr=left-right; fll=left-left;
b=2");
  
      CuAssertPtrNotNull(tc, j);
  }
  
  static void jar_table_get(CuTest *tc)
  {
      const char *val;
  
      val = apreq_table_get(j,"a");
      CuAssertStrEquals(tc,"1",val);
      val = apreq_table_get(j,"b");
      CuAssertStrEquals(tc,"2",val);
  
      val = apreq_table_get(j,"foo");
      CuAssertStrEquals(tc,"bar",val);
      val = apreq_table_get(j,"fl");
      CuAssertStrEquals(tc,"left",val);
      val = apreq_table_get(j,"fr");
      CuAssertStrEquals(tc,"right",val);
      val = apreq_table_get(j,"frl");
      CuAssertStrEquals(tc,"right-left",val);
      val = apreq_table_get(j,"flr");
      CuAssertStrEquals(tc,"left-right",val);
      val = apreq_table_get(j,"fll");
      CuAssertStrEquals(tc,"left-left",val);
  }
  
  
  static void netscape_cookie(CuTest *tc)
  {
      apreq_cookie_t *c;
      apreq_cookie_version_t version = NETSCAPE;
      char *expires = apreq_expires(p,"+1y", NSCOOKIE);
  
      c = apreq_cookie(j,"foo");
      CuAssertStrEquals(tc,"bar",apreq_cookie_value(c));
      CuAssertIntEquals(tc, version,c->version);
  
      CuAssertStrEquals(tc,"foo=bar", apreq_cookie_as_string(p,c));
      c->domain = apr_pstrdup(p, "example.com");
      CuAssertStrEquals(tc,"foo=bar; domain=example.com", 
                        apreq_cookie_as_string(p,c));
  
      c->path = apr_pstrdup(p, "/quux");
      CuAssertStrEquals(tc, "foo=bar; path=/quux; domain=example.com",
                        apreq_cookie_as_string(p,c));
  
      apreq_cookie_expires(c, "+1y");
      CuAssertStrEquals(tc,apr_pstrcat(p,
                           "foo=bar; path=/quux; domain=example.com; expires=", 
                           expires, NULL), apreq_cookie_as_string(p,c));
  
  }
  
  
  static void rfc_cookie(CuTest *tc)
  {
      apreq_cookie_t *c = apreq_make_cookie(NULL,RFC,"rfc",3,"out",3);
      apreq_cookie_version_t version = RFC;
      long expires = apreq_atol("+3m");
  
      CuAssertStrEquals(tc,"out",apreq_cookie_value(c));
      CuAssertIntEquals(tc, version,c->version);
  
      CuAssertStrEquals(tc,"rfc=out; Version=1", apreq_cookie_as_string(p,c));
      c->domain = apr_pstrdup(p, "example.com");
      CuAssertStrEquals(tc,"rfc=out; Version=1; domain=example.com", 
                        apreq_cookie_as_string(p,c));
  
      c->path = apr_pstrdup(p, "/quux");
      CuAssertStrEquals(tc, 
                "rfc=out; Version=1; path=/quux; domain=example.com",
                        apreq_cookie_as_string(p,c));
  
      apreq_cookie_expires(c, "+3m");
      CuAssertStrEquals(tc,apr_psprintf(p,
           "rfc=out; Version=1; path=/quux; domain=example.com; max-age=%ld", 
                 expires), apreq_cookie_as_string(p,c));
  
  }
  
  
  CuSuite *testcookie(void)
  {
      CuSuite *suite = CuSuiteNew("Cookie");
  
      SUITE_ADD_TEST(suite, jar_make);
      SUITE_ADD_TEST(suite, jar_table_get);
      SUITE_ADD_TEST(suite, netscape_cookie);
      SUITE_ADD_TEST(suite, rfc_cookie);
      return suite;
  }
  
  
  
  

Mime
View raw message