Author: rhuijben Date: Tue Nov 17 23:19:45 2015 New Revision: 1714906 URL: http://svn.apache.org/viewvc?rev=1714906&view=rev Log: Make the new logging framework capable of handling incoming connections and use this to enable logging in the httpd test app.
* config_store.c (conn_key_for_conn): Use pointer value instead of integer value to properly handle 64 bit platforms where int is 32 bit. (apr handles %p specifically. %pp is like the usual %p) (conn_key_for_client): New function. (serf__config_store_get_client_config): New function, based on serf__config_store_get_config. * incoming.c (client_connected): Resolve TODO. (serf_incoming_create2): Initialize config. * serf_private.h (serf__config_store_get_client_config): New function. * test/serf_httpd.c (apr_getopt_option_t): Tweak some options. (main): Allow logging. Use -V for version, -v for verbose. Modified: serf/trunk/config_store.c serf/trunk/incoming.c serf/trunk/serf_private.h serf/trunk/test/serf_httpd.c Modified: serf/trunk/config_store.c URL: http://svn.apache.org/viewvc/serf/trunk/config_store.c?rev=1714906&r1=1714905&r2=1714906&view=diff ============================================================================== --- serf/trunk/config_store.c (original) +++ serf/trunk/config_store.c Tue Nov 17 23:19:45 2015 @@ -70,7 +70,7 @@ add_or_replace_entry(serf__config_hdr_t entry->key = key; entry->value = value; entry->next = NULL; - + if (last) last->next = entry; else @@ -106,9 +106,18 @@ static const char * conn_key_for_conn(se apr_pool_t *pool) { /* Key needs to be unique per connection, so stringify its pointer value */ - return apr_psprintf(pool, "%x", (unsigned int)conn); + return apr_psprintf(pool, "%pp", conn); } +/* Defines the key to use for per connection settings */ +static const char * conn_key_for_client(serf_incoming_t *incoming, + apr_pool_t *pool) +{ + /* Key needs to be unique per connection, so stringify its pointer value */ + return apr_psprintf(pool, "%pp", incoming); +} + + /* TODO: when will this be released? Related config to a specific lifecyle: connection or context */ apr_status_t serf__config_store_get_config(serf_context_t *ctx, @@ -162,6 +171,50 @@ apr_status_t serf__config_store_get_conf apr_pool_destroy(tmp_pool); } + + *config = cfg; + + return APR_SUCCESS; +} + +apr_status_t serf__config_store_get_client_config(serf_context_t *ctx, + serf_incoming_t *client, + serf_config_t **config, + apr_pool_t *out_pool) +{ + serf__config_store_t *config_store = &ctx->config_store; + + serf_config_t *cfg = apr_pcalloc(out_pool, sizeof(serf_config_t)); + cfg->ctx_pool = ctx->pool; + cfg->per_context = config_store->global_per_context; + + if (client) { + const char *client_key; + serf__config_hdr_t *per_conn; + apr_pool_t *tmp_pool; + apr_status_t status; + + cfg->conn_pool = client->pool; + + if ((status = apr_pool_create(&tmp_pool, out_pool)) != APR_SUCCESS) + return status; + + /* Find the config values for this connection, create empty structure + if needed */ + client_key = conn_key_for_client(client, tmp_pool); + per_conn = apr_hash_get(config_store->global_per_conn, client_key, + APR_HASH_KEY_STRING); + if (!per_conn) { + per_conn = create_config_hdr(client->pool); + apr_hash_set(config_store->global_per_conn, + apr_pstrdup(client->pool, client_key), + APR_HASH_KEY_STRING, per_conn); + } + cfg->per_conn = per_conn; + cfg->per_host = NULL; + + apr_pool_destroy(tmp_pool); + } *config = cfg; Modified: serf/trunk/incoming.c URL: http://svn.apache.org/viewvc/serf/trunk/incoming.c?rev=1714906&r1=1714905&r2=1714906&view=diff ============================================================================== --- serf/trunk/incoming.c (original) +++ serf/trunk/incoming.c Tue Nov 17 23:19:45 2015 @@ -41,8 +41,20 @@ static apr_status_t client_connected(ser /* serf_context_t *ctx = client->ctx; */ apr_status_t status; serf_bucket_t *ostream; + apr_sockaddr_t *sa; - /* ### TODO: Store ip address in config for logging */ + if (apr_socket_addr_get(&sa, APR_LOCAL, client->skt) == APR_SUCCESS) { + char buf[48]; + if (!apr_sockaddr_ip_getbuf(buf, sizeof(buf), sa)) + serf_config_set_stringf(client->config, SERF_CONFIG_CONN_LOCALIP, + "%s:%d", buf, sa->port); + } + if (apr_socket_addr_get(&sa, APR_REMOTE, client->skt) == APR_SUCCESS) { + char buf[48]; + if (!apr_sockaddr_ip_getbuf(buf, sizeof(buf), sa)) + serf_config_set_stringf(client->config, SERF_CONFIG_CONN_REMOTEIP, + "%s:%d", buf, sa->port); + } serf__log(LOGLVL_DEBUG, LOGCOMP_CONN, __FILE__, client->config, "socket for client 0x%x connected\n", client); @@ -718,6 +730,7 @@ apr_status_t serf_incoming_create2( apr_status_t rv; apr_pool_t *ic_pool; serf_incoming_t *ic; + serf_config_t *config; apr_pool_create(&ic_pool, pool); @@ -762,14 +775,12 @@ apr_status_t serf_incoming_create2( ic->seen_in_pollset = 0; /* Store the connection specific info in the configuration store */ - /* ### Doesn't work... Doesn't support listeners yet*/ - /*rv = serf__config_store_get_config(ctx, ic, &config, pool); + rv = serf__config_store_get_client_config(ctx, ic, &config, pool); if (rv) { - apr_pool_destroy(l->pool); - return rv; + apr_pool_destroy(ic->pool); + return rv; } - ic->config = config;*/ - ic->config = NULL; /* FIX!! */ + ic->config = config; rv = ctx->pollset_add(ctx->pollset_baton, &ic->desc, &ic->baton); Modified: serf/trunk/serf_private.h URL: http://svn.apache.org/viewvc/serf/trunk/serf_private.h?rev=1714906&r1=1714905&r2=1714906&view=diff ============================================================================== --- serf/trunk/serf_private.h (original) +++ serf/trunk/serf_private.h Tue Nov 17 23:19:45 2015 @@ -282,6 +282,13 @@ apr_status_t serf__config_store_get_conf serf_config_t **config, apr_pool_t *out_pool); +/* Same thing, but for incoming connections */ +apr_status_t serf__config_store_get_client_config(serf_context_t *ctx, + serf_incoming_t *client, + serf_config_t **config, + apr_pool_t *out_pool); + + /* Cleans up all connection specific configuration values */ apr_status_t serf__config_store_remove_connection(serf__config_store_t config_store, Modified: serf/trunk/test/serf_httpd.c URL: http://svn.apache.org/viewvc/serf/trunk/test/serf_httpd.c?rev=1714906&r1=1714905&r2=1714906&view=diff ============================================================================== --- serf/trunk/test/serf_httpd.c (original) +++ serf/trunk/test/serf_httpd.c Tue Nov 17 23:19:45 2015 @@ -276,8 +276,9 @@ static const apr_getopt_option_t options { { "help", 'h', 0, "Display this help" }, - { NULL, 'v', 0, "Display version" }, + { "version", 'V', 0, "Display version" }, { "listen", 'l', 1, "<[protocol,][host:]port> Configure listener"}, + { "verbose", 'v', 0, "Enable debug logging" }, /* { NULL, 'H', 0, "Print response headers" }, { NULL, 'n', 1, "<count> Fetch URL <count> times" }, { NULL, 'c', 1, "<count> Use <count> concurrent connections" }, @@ -290,7 +291,6 @@ static const apr_getopt_option_t options { "cert", CERTFILE, 1, "<file> Use SSL client certificate <file>" }, { "certpwd", CERTPWD, 1, "<password> Password for the SSL client certificate" }, { NULL, 'r', 1, "<header:value> Use <header:value> as request header" }, - { "debug", 'd', 0, "Enable debugging" }, { "http2", HTTP2FLAG, 0, "Enable http2 (https only) (Experimental)" }, { "h2direct",H2DIRECT, 0, "Enable h2direct (Experimental)" },*/ @@ -380,6 +380,7 @@ int main(int argc, const char **argv) apr_getopt_t *opt; apr_allocator_t *allocator; int opt_c; + int verbose = 0; const char *opt_arg; const char *root_dir; @@ -427,12 +428,16 @@ int main(int argc, const char **argv) print_usage(scratch_pool); exit(0); break; - case 'v': + case 'V': puts("Serf version: " SERF_VERSION_STRING); exit(0); case 'l': configure_listener(context, &app_ctx, opt_arg, app_pool); break; + case 'v': + verbose++; + break; + default: break; } @@ -445,6 +450,24 @@ int main(int argc, const char **argv) root_dir = argv[opt->ind]; + /* Setup debug logging */ + if (verbose) { + serf_log_output_t *output; + apr_status_t status; + + status = serf_logging_create_stream_output( + &output, + context, + SERF_LOG_INFO, + SERF_LOGCOMP_ALL_MSG & ~(SERF_LOGCOMP_RAWMSG | SERF_LOGCOMP_SSLMSG), + SERF_LOG_DEFAULT_LAYOUT, + stderr, + app_pool); + + if (!status) + serf_logging_add_output(context, output); + } + while (1) { apr_pool_clear(scratch_pool); status = serf_context_run(context, apr_time_from_msec(50),