apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject cvs commit: apr/test testud.c Makefile.in testcontext.c
Date Sat, 07 Jul 2001 13:03:47 GMT
dreid       01/07/07 06:03:46

  Modified:    include  apr_sms.h
               memory/unix apr_sms.c sms_private.h
               test     Makefile.in
  Added:       test     testud.c
  Removed:     test     testcontext.c
  Log:
  Few changes, mainly to add more support for sms :)
  - add apr_sms_userdata_get/set routines
  - change testcontext into testud as all it does is test user data
  - add a test for sms user data into testud
  - remove testcontext as we haven't been calling our memory contexts
    for a very long time now :)
  
  Revision  Changes    Path
  1.35      +21 -0     apr/include/apr_sms.h
  
  Index: apr_sms.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_sms.h,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- apr_sms.h	2001/07/07 12:26:31	1.34
  +++ apr_sms.h	2001/07/07 13:03:45	1.35
  @@ -289,6 +289,27 @@
    */
   APR_DECLARE(apr_abortfunc_t) apr_sms_get_abort(apr_sms_t *sms);
   
  +/**
  + * Set user data into the current sms.
  + * @param data The user data to insert
  + * @param key The key to assign to this data
  + * @param cleanup The cleanup program to use when cleaning up the data
  + * @param sms The sms to inert the data into
  + */
  +APR_DECLARE(apr_status_t) apr_sms_userdata_set(const void *data,
  +                                               const char *key,
  +                                               apr_status_t (*cleanup)(void*),
  +                                               apr_sms_t *sms);
  +
  +/**
  + * Get user data from an sms using the key it was registered with
  + * @param data A pointer to the returned data
  + * @param key The key to use to identify the data
  + * @param sms The sms to get the data from
  + */
  +APR_DECLARE(apr_status_t) apr_sms_userdata_get(void **data, const char *key,
  +                                               apr_sms_t *sms);
  +
   /*
    * memory system cleanup management functions
    */
  
  
  
  1.45      +35 -1     apr/memory/unix/apr_sms.c
  
  Index: apr_sms.c
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/apr_sms.c,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- apr_sms.c	2001/07/07 12:26:32	1.44
  +++ apr_sms.c	2001/07/07 13:03:45	1.45
  @@ -64,9 +64,12 @@
   #include "apr_general.h"
   #include "apr_sms.h"
   #include <stdlib.h>
  -#include "sms_private.h"
  +#include "apr_hash.h"
  +#include "apr_strings.h"
   #include "apr_portable.h"
   
  +#include "sms_private.h"
  +
   #ifdef APR_ASSERT_MEMORY
   #include <assert.h>
   #endif
  @@ -920,6 +923,37 @@
   APR_DECLARE(apr_abortfunc_t) apr_sms_get_abort(apr_sms_t *sms)
   {
       return sms->apr_abort;
  +}
  +
  +APR_DECLARE(apr_status_t) apr_sms_userdata_set(const void *data,
  +                                               const char *key,
  +                                               apr_status_t (*cleanup)(void*),
  +                                               apr_sms_t *sms)
  +{
  +    apr_size_t keylen = strlen(key);
  +
  +    if (sms->prog_data == NULL)
  +        sms->prog_data = apr_hash_make(sms->pool);
  +
  +    if (apr_hash_get(sms->prog_data, key, keylen) == NULL) {
  +        char *new_key = apr_pstrdup((apr_pool_t*)sms->pool, key);
  +        apr_hash_set(sms->prog_data, new_key, keylen, data);
  +    } else {
  +        apr_hash_set(sms->prog_data, key, keylen, data);
  +    }
  +
  +    apr_sms_cleanup_register(sms, APR_GENERAL_CLEANUP, data, cleanup);
  +    return APR_SUCCESS;
  +}
  +
  +APR_DECLARE(apr_status_t) apr_sms_userdata_get(void **data, const char *key,
  +                                               apr_sms_t *sms)
  +{
  +    if (sms->prog_data == NULL)
  +        *data = NULL;
  +    else
  +        *data = apr_hash_get(sms->prog_data, key, strlen(key));
  +    return APR_SUCCESS;
   }
   
   #if APR_DEBUG_SHOW_STRUCTURE
  
  
  
  1.6       +1 -0      apr/memory/unix/sms_private.h
  
  Index: sms_private.h
  ===================================================================
  RCS file: /home/cvs/apr/memory/unix/sms_private.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- sms_private.h	2001/07/07 12:26:32	1.5
  +++ sms_private.h	2001/07/07 13:03:45	1.6
  @@ -94,6 +94,7 @@
       apr_status_t (*unlock_fn)      (apr_sms_t *sms);
   
       apr_status_t (*apr_abort)(int retcode);
  +    struct apr_hash_t *prog_data;
   
   #if APR_HAS_THREADS    
       apr_status_t (*thread_register_fn)   (apr_sms_t *sms, 
  
  
  
  1.59      +3 -3      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- Makefile.in	2001/07/07 07:55:18	1.58
  +++ Makefile.in	2001/07/07 13:03:46	1.59
  @@ -13,7 +13,7 @@
   	testlock@EXEEXT@ \
   	testtime@EXEEXT@ \
   	testargs@EXEEXT@ \
  -	testcontext@EXEEXT@ \
  +	testud@EXEEXT@ \
   	testmmap@EXEEXT@ \
   	testshmem@EXEEXT@ \
   	testpipe@EXEEXT@ \
  @@ -69,8 +69,8 @@
   testargs@EXEEXT@: testargs.lo $(LOCAL_LIBS)
   	$(LINK) testargs.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testcontext@EXEEXT@: testcontext.lo $(LOCAL_LIBS)
  -	$(LINK) testcontext.lo $(LOCAL_LIBS) $(ALL_LIBS)
  +testud@EXEEXT@: testud.lo $(LOCAL_LIBS)
  +	$(LINK) testud.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
   testproc@EXEEXT@: testproc.lo $(LOCAL_LIBS)
   	$(LINK) testproc.lo $(LOCAL_LIBS) $(ALL_LIBS)
  
  
  
  1.1                  apr/test/testud.c
  
  Index: testud.c
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2001 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 <stdio.h>
  #include <stdlib.h>
  #include "apr_file_io.h"
  #include "apr_errno.h"
  #include "apr_general.h"
  #include "apr_lib.h"
  #include "apr_strings.h"
  #include "apr_sms.h"
  #include "test_apr.h"
  
  static apr_status_t string_cleanup(void *data)
  {
      return APR_SUCCESS;
  }
  
  int main(void)
  {
      apr_pool_t *pool;
      apr_sms_t *sms;
      char *testdata;
      char *retdata;
  
      printf("APR User Data Test\n==================\n\n");
  
      STD_TEST_NEQ("Initializing APR", apr_initialize())
      atexit(apr_terminate);
  
      STD_TEST_NEQ("Creating a pool", apr_pool_create(&pool, NULL))
      STD_TEST_NEQ("Creating an sms", apr_sms_std_create(&sms))
  
      testdata = apr_pstrdup(pool, "This is a test\n");
  
      printf("Testing pool\n");
      STD_TEST_NEQ("    Setting user data into the pool",
            apr_pool_userdata_set(testdata, "TEST", string_cleanup, pool))
      
      STD_TEST_NEQ("    Getting user data from the pool",
            apr_pool_userdata_get((void **)&retdata, "TEST", pool))
  
      TEST_NEQ("    Checking the data we got", strcmp(testdata, retdata),
               0, "OK","Failed :(")
  
      printf("Testing SMS\n");
   
      STD_TEST_NEQ("    Setting user data into the pool",
            apr_sms_userdata_set(testdata, "TEST", string_cleanup, sms))
      
      STD_TEST_NEQ("    Getting user data from the pool",
            apr_sms_userdata_get((void **)&retdata, "TEST", sms))
  
      TEST_NEQ("    Checking the data we got", strcmp(testdata, retdata),
               0, "OK","Failed :(")
  
      printf("\nTest complete\n");
      return 1;
  }
  
  
  

Mime
View raw message