static char *ssl_expr_eval_func_file(request_rec *r, char *filename) { FILE *fp; char *buf; int len; if ((fp = ap_pfopen(r->pool, filename, "r")) == NULL) { ssl_expr_error = "Cannot open file"; return ""; } fseek(fp, 0, SEEK_END); len = ftell(fp); if (len == 0) { buf = (char *)ap_palloc(r->pool, sizeof(char) * 1); *buf = NUL; } else { if ((buf = (char *)ap_palloc(r->pool, sizeof(char) * (len+1))) == NULL) { ssl_expr_error = "Cannot allocate memory"; ap_pfclose(r->pool, fp); return ""; } fseek(fp, 0, SEEK_SET); if (fread(buf, len, 1, fp) == 0) { ssl_expr_error = "Cannot read from file"; fclose(fp); return (""); } buf[len] = NUL; } ap_pfclose(r->pool, fp); return buf; }
static int asis_handler(request_rec *r) { FILE *f; const char *location; r->allowed |= (1 << M_GET); if (r->method_number != M_GET) return DECLINED; if (r->finfo.st_mode == 0) { ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r, "File does not exist: %s", r->filename); return NOT_FOUND; } f = ap_pfopen(r->pool, r->filename, "r"); if (f == NULL) { ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "file permissions deny server access: %s", r->filename); return FORBIDDEN; } ap_scan_script_header_err(r, f, NULL); location = ap_table_get(r->headers_out, "Location"); if (location && location[0] == '/' && ((r->status == HTTP_OK) || ap_is_HTTP_REDIRECT(r->status))) { ap_pfclose(r->pool, f); /* Internal redirect -- fake-up a pseudo-request */ r->status = HTTP_OK; /* This redirect needs to be a GET no matter what the original * method was. */ r->method = ap_pstrdup(r->pool, "GET"); r->method_number = M_GET; ap_internal_redirect_handler(location, r); return OK; } ap_send_http_header(r); if (!r->header_only) ap_send_fd(f, r); ap_pfclose(r->pool, f); return OK; }
static void preserve_entry(request_rec *r, const char *query) { logsql_state *cls = ap_get_module_config(r->server->module_config, &log_sql_module); #if defined(WITH_APACHE20) apr_file_t *fp; apr_status_t result; #elif defined(WITH_APACHE13) FILE *fp; int result; #endif /* If preserve file is disabled bail out */ if (global_config.disablepreserve) return; #if defined(WITH_APACHE20) result = apr_file_open(&fp, cls->preserve_file,APR_APPEND | APR_WRITE | APR_CREATE, APR_OS_DEFAULT, r->pool); #elif defined(WITH_APACHE13) fp = ap_pfopen(r->pool, cls->preserve_file, "a"); result = (fp)?0:errno; #endif if (result != APR_SUCCESS) { log_error(APLOG_MARK, APLOG_ERR, result, r->server, "attempted append of local preserve file '%s' but failed.",cls->preserve_file); } else { #if defined(WITH_APACHE20) apr_file_printf(fp,"%s;\n", query); apr_file_close(fp); #elif defined(WITH_APACHE13) fprintf(fp,"%s;\n", query); ap_pfclose(r->pool, fp); #endif log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server, "mod_log_sql: entry preserved in %s", cls->preserve_file); } }
static void remove_tmpfile(void *data) { ApacheUpload *upload = (ApacheUpload *) data; ApacheRequest *req = upload->req; if( ap_pfclose(req->r->pool, upload->fp) ) ap_log_rerror(REQ_ERROR, "[libapreq] close error on '%s'", upload->tempname); #ifndef DEBUG if( remove(upload->tempname) ) ap_log_rerror(REQ_ERROR, "[libapreq] remove error on '%s'", upload->tempname); #endif free(upload->tempname); }
static void diag_core(const char *category, int level, const char *fmt, va_list args) { size_t len = 0; const THash *hl = 0; char errstr[MAX_STRING_LEN]; if (!diag_file) { return; } /* try and find the specific category */ hl = HashFind(diag_levels, (char *)category); if (!hl) { /* didn't find specific category - look for default */ hl = defaultHashCell; } if (!hl || ((int)hl->t_val < level )) { /* either no match at all or the levels were off */ return; } #if 0 if( s->diag_rollover_time ) { if( s->diag_rollover_time < ap_time() ) { ap_pfclose( s->pool,s->diagfile ); ap_diag_rollover_file( s,s->pool ); } } #endif { char dateStr[32]; ap_gmtime_str(dateStr); len = snprintf(errstr, sizeof(errstr), "[%s] <diag:%s,%d> ", dateStr, category, level); len += vsnprintf(errstr+len, sizeof(errstr)-len, fmt, args); } pthread_mutex_lock(&diag_file_mutex); { write(diag_file, errstr, len); write(diag_file, "\n", 1); } pthread_mutex_unlock(&diag_file_mutex); }
API_EXPORT(void) ap_close_piped_log (piped_log *pl) { ap_pfclose (pl->p, pl->write_f); }