/****************************************** * table example with apr * Sylvain Marechal * 25/10/2005 *****************************************/ #include "apr_general.h" #include "apr_tables.h" /********************************************* * table callback *********************************************/ int table_do_callback(void *rec, const char *key, const char *value) { printf( "user data: '%s', key: '%s', value: '%s'\n", (char *)rec, key, value ); return 1; // 0 to stop iteration } /********************************************* * tables * Note table can only store stex data ********************************************/ void test_table( apr_pool_t * pool ) { apr_table_t * t; int nb_elems = 10; int i; char key[2] = {0}; char value[2] = {0}; const char * val = 0; /* Create table */ t = apr_table_make( pool, nb_elems ); /* Add 10 objects */ for( i = 0; i < nb_elems; i ++ ) { key[0] = 'A' + i; value[0] = 'a' + i; printf( "key: '%s', val: '%s'\n", key, value ); apr_table_add( t, key, value ); } /* Verify count */ apr_table_do( table_do_callback, (void *)"A user data", t, NULL ); /* Find the 10 objects */ for( i = 0; i < nb_elems; i ++ ) { key[0] = 'A' + i; val = apr_table_get( t, key ); printf( "value for key '%s' is '%s'\n", key, val ); } } /********************************************* * main ********************************************/ int main( int argc, char * argv[] ) { apr_pool_t *pool; if (apr_initialize() != APR_SUCCESS) { printf( "Could not initialize\n"); exit(-1); } if (apr_pool_create(&pool, NULL) != APR_SUCCESS) { printf( "Could not allocate pool\n"); exit( -1); } test_table( pool ); apr_pool_destroy( pool ); return 0; }