static const char *set_rotated_logs(cmd_parms *cmd, void *dummy, int flag) { log_options *ls = ap_get_module_config(cmd->server->module_config, &log_rotate_module); if (flag) { /* Always hook the writer functions when we're enabled even if we've * done it already. We can't unhook which means that once we've been * enabled we become responsible for all transfer log output. Note that * a subsequent BufferedLogs On in conf will clobber these hooks and * disable us. */ APR_OPTIONAL_FN_TYPE(ap_log_set_writer_init) *set_writer_init; APR_OPTIONAL_FN_TYPE(ap_log_set_writer) *set_writer; set_writer_init = APR_RETRIEVE_OPTIONAL_FN(ap_log_set_writer_init); set_writer = APR_RETRIEVE_OPTIONAL_FN(ap_log_set_writer); if (NULL != set_writer_init && NULL != set_writer) { set_writer_init(ap_rotated_log_writer_init); set_writer(ap_rotated_log_writer); ls->enabled = 1; } else { ap_log_error(APLOG_MARK, APLOG_ERR, APR_SUCCESS, cmd->server, "can't install log rotator - ap_log_set_writer not available"); ls->enabled = 0; } } else { ls->enabled = 0; } return NULL; }
static const char *cmd_spread_logs(cmd_parms *cmd, void *dummy, int flag) { log_spread2_options *opt = ap_get_module_config(cmd->server->module_config, &log_spread2_module); const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); if (err) { return err; } APR_OPTIONAL_FN_TYPE(ap_log_set_writer_init) *set_writer_init; APR_OPTIONAL_FN_TYPE(ap_log_set_writer) *set_writer; set_writer_init = APR_RETRIEVE_OPTIONAL_FN(ap_log_set_writer_init); set_writer = APR_RETRIEVE_OPTIONAL_FN(ap_log_set_writer); if (set_writer_init == NULL || set_writer == NULL) { return MNAME ": can't install log writer - ap_log_set_writer not available"; } SP_disconnect(opt->mbox); opt->enabled = 0; if (flag) { apr_status_t rv = SP_connect(opt->name, 0, 0, 0, &opt->mbox, opt->priv); if (rv != ACCEPT_SESSION) { ap_log_error(APLOG_MARK, APLOG_ERR, rv, cmd->server, MNAME ": could not open connection to daemon."); return NULL; } opt->old_writer_init = set_writer_init(ap_spread_log_writer_init); opt->old_writer = set_writer(ap_spread_log_writer); opt->enabled = 1; } else { if (opt->old_writer_init) { set_writer_init(opt->old_writer_init); opt->old_writer_init = NULL; } if (opt->old_writer) { set_writer(opt->old_writer); opt->old_writer = NULL; } } return NULL; }
// Get the full URI of the request_rec's request location // clean_params specifies whether or not all openid.* and modauthopenid.* params should be cleared static void full_uri(request_rec *r, std::string& result, modauthopenid_config *s_cfg, bool clean_params=false) { std::string hostname(r->hostname); std::string uri(r->uri); apr_port_t i_port = ap_get_server_port(r); // Fetch the APR function for determining if we are looking at an https URL APR_OPTIONAL_FN_TYPE(ssl_is_https) *using_https = APR_RETRIEVE_OPTIONAL_FN(ssl_is_https); std::string prefix = (using_https != NULL && using_https(r->connection)) ? "https://" : "http://"; char *port = apr_psprintf(r->pool, "%lu", (unsigned long) i_port); std::string s_port = (i_port == 80 || i_port == 443) ? "" : ":" + std::string(port); std::string args; if(clean_params) { opkele::params_t params; if(r->args != NULL) params = modauthopenid::parse_query_string(std::string(r->args)); modauthopenid::remove_openid_vars(params); args = params.append_query("", ""); } else { args = (r->args == NULL) ? "" : "?" + std::string(r->args); } if(s_cfg->server_name == NULL) result = prefix + hostname + s_port + uri + args; else result = std::string(s_cfg->server_name) + uri + args; }
int deepcgi_handler( request_rec* inpRequest ) { if ( !inpRequest->handler || strcmp( inpRequest->handler, "deepcgi-handler" )) { return DECLINED; } const char* request_method = inpRequest->method; const char* request_uri = inpRequest->unparsed_uri; const char* protocol = inpRequest->protocol; const char* http_host = inpRequest->hostname; const char* user_agent = apr_table_get( inpRequest->headers_in, "User-Agent" ); setenv( "MAHIMAHI_CHDIR", config.working_dir, TRUE ); setenv( "MAHIMAHI_RECORD_PATH", config.recording_dir, TRUE ); setenv( "REQUEST_METHOD", request_method, TRUE ); setenv( "REQUEST_URI", request_uri, TRUE ); setenv( "SERVER_PROTOCOL", protocol, TRUE ); setenv( "HTTP_HOST", http_host, TRUE ); if ( user_agent != NULL ) { setenv( "HTTP_USER_AGENT", user_agent, TRUE ); } /* check if connection is HTTPS */ /* see bug report at http://modpython.org/pipermail/mod_python/2006-February/020197.html */ /* taken from fix at https://issues.apache.org/jira/secure/attachment/12321011/requestobject.c.patch */ APR_DECLARE_OPTIONAL_FN(int, ssl_is_https, (conn_rec *)); APR_OPTIONAL_FN_TYPE(ssl_is_https) *optfn_is_https = APR_RETRIEVE_OPTIONAL_FN(ssl_is_https); if ( optfn_is_https ) { if ( optfn_is_https( inpRequest->connection ) ) { setenv( "HTTPS", "1", TRUE ); } } FILE* fp = popen( replayserver_filename, "r" ); if ( fp == NULL ) { // "Error encountered while running script" return HTTP_INTERNAL_SERVER_ERROR; } char line[HUGE_STRING_LEN]; struct ap_filter_t *cur; // Get rid of all filters up through protocol...since we // haven't parsed off the headers, there is no way they can // work cur = inpRequest->proto_output_filters; while (cur && cur->frec->ftype < AP_FTYPE_CONNECTION) { cur = cur->next; } inpRequest->output_filters = inpRequest->proto_output_filters = cur; // Write headers + body int num_bytes_read; do { num_bytes_read = fread( line, sizeof(char), HUGE_STRING_LEN, fp ); int num_bytes_left = num_bytes_read; while ( num_bytes_left > 0 ) { int offset = num_bytes_read - num_bytes_left; int num_bytes_written = ap_rwrite( line + offset, num_bytes_left, inpRequest ); if ( num_bytes_written == -1 ) { // "Error encountered while writing" return HTTP_INTERNAL_SERVER_ERROR; } num_bytes_left -= num_bytes_written; } } while ( num_bytes_read == HUGE_STRING_LEN ); // To ensure that connection is kept-alive ap_set_keepalive( inpRequest ); pclose( fp ); return OK; }