static apr_status_t dbm_open_type(apr_dbm_type_t const* * vtable, const char *type, apr_pool_t *pool) { #if !APU_DSO_BUILD *vtable = NULL; if (!strcasecmp(type, "default")) *vtable = &DBM_VTABLE; #if APU_HAVE_DB else if (!strcasecmp(type, "db")) *vtable = &apr_dbm_type_db; #endif else if (*type && !strcasecmp(type + 1, "dbm")) { #if APU_HAVE_GDBM if (*type == 'G' || *type == 'g') *vtable = &apr_dbm_type_gdbm; #endif #if APU_HAVE_NDBM if (*type == 'N' || *type == 'n') *vtable = &apr_dbm_type_ndbm; #endif #if APU_HAVE_SDBM if (*type == 'S' || *type == 's') *vtable = &apr_dbm_type_sdbm; #endif /* avoid empty block */ ; } if (*vtable) return APR_SUCCESS; return APR_ENOTIMPL; #else /* APU_DSO_BUILD */ char modname[32]; char symname[34]; apr_dso_handle_sym_t symbol; apr_status_t rv; int usertype = 0; if (!strcasecmp(type, "default")) type = DBM_NAME; else if (!strcasecmp(type, "db")) type = "db"; else if (*type && !strcasecmp(type + 1, "dbm")) { if (*type == 'G' || *type == 'g') type = "gdbm"; else if (*type == 'N' || *type == 'n') type = "ndbm"; else if (*type == 'S' || *type == 's') type = "sdbm"; } else usertype = 1; if (apr_atomic_inc32(&initialised)) { apr_atomic_set32(&initialised, 1); /* prevent wrap-around */ while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */ ; } else { apr_pool_t *parent; /* Top level pool scope, need process-scope lifetime */ for (parent = apr_pool_parent_get(pool); parent && parent != pool; parent = apr_pool_parent_get(pool)) pool = parent; /* deprecate in 2.0 - permit implicit initialization */ apu_dso_init(pool); drivers = apr_hash_make(pool); apr_hash_set(drivers, "sdbm", APR_HASH_KEY_STRING, &apr_dbm_type_sdbm); apr_pool_cleanup_register(pool, NULL, dbm_term, apr_pool_cleanup_null); apr_atomic_dec32(&in_init); } rv = apu_dso_mutex_lock(); if (rv) { *vtable = NULL; return rv; } *vtable = apr_hash_get(drivers, type, APR_HASH_KEY_STRING); if (*vtable) { apu_dso_mutex_unlock(); return APR_SUCCESS; } /* The driver DSO must have exactly the same lifetime as the * drivers hash table; ignore the passed-in pool */ pool = apr_hash_pool_get(drivers); #if defined(NETWARE) apr_snprintf(modname, sizeof(modname), "dbm%s.nlm", type); #elif defined(WIN32) || defined (__CYGWIN__) apr_snprintf(modname, sizeof(modname), "apr_dbm_%s-" APU_STRINGIFY(APU_MAJOR_VERSION) ".dll", type); #else apr_snprintf(modname, sizeof(modname), "apr_dbm_%s-" APU_STRINGIFY(APU_MAJOR_VERSION) ".so", type); #endif apr_snprintf(symname, sizeof(symname), "apr_dbm_type_%s", type); rv = apu_dso_load(NULL, &symbol, modname, symname, pool); if (rv == APR_SUCCESS || rv == APR_EINIT) { /* previously loaded?!? */ *vtable = symbol; if (usertype) type = apr_pstrdup(pool, type); apr_hash_set(drivers, type, APR_HASH_KEY_STRING, *vtable); rv = APR_SUCCESS; } else *vtable = NULL; apu_dso_mutex_unlock(); return rv; #endif /* APU_DSO_BUILD */ }
/** * Process data the parser has stored in the input buffer. */ static apr_status_t alp2_pp_process_internal(alp2_pp_t *alp_pp) { /* Do not proceed if we've previously * encountered a fatal error. */ if (alp_pp->errored != 0) { return ALP2_ERROR_FATAL; } if (alp_pp->done) { return ALP2_DONE; } /* Go back straight away if we don't have anything to work with. */ if (alp_pp->input_len == 0) { return ALP2_NEED_DATA; } while (alp_pp->input_pos < alp_pp->input_len) { int c; if (alp_pp->done) { return ALP2_DONE; } if (alp_pp->line_pos >= alp_pp->line_size) { /* Our line buffer is full with the * line incomplete. */ alp2_pp_process_part_data(alp_pp); /* Reset line buffer . */ alp_pp->line_pos = 0; alp_pp->line_has_start = 0; alp_pp->line_offset = alp_pp->current_offset; } /* Consume one byte. */ c = alp_pp->input_buf[alp_pp->input_pos]; alp_pp->input_pos++; alp_pp->current_offset++; /* Copy the byte to the line buffer. */ alp_pp->line_buf[alp_pp->line_pos] = c; alp_pp->line_pos++; /* Are we at the end of a line? */ if (c == '\n') { if (alp_pp->line_has_start) { /* We have one complete line. */ int id = alp2_pp_is_boundary_line(alp_pp); if (id != 0) { /* The line is a boundary. */ /* Finish with the previous part, if any. */ if (alp_pp->current_part != NULL) { /* Update the MD5 context. */ apr_md5_update(alp_pp->current_entry->md5_context, &alp_pp->line_buf[0], alp_pp->line_pos - 1); /* Event PART_END. */ if (alp_pp->callback != NULL) { if (alp_pp->callback(alp_pp, ALP2_EVENT_PART_END) == 0) { alp_pp->done = 1; } } /* Add part to the current entry. */ *(alp2_pp_part_t **)apr_array_push(alp_pp->current_entry->parts) = alp_pp->current_part; /* Delete part. */ alp_pp->current_part = NULL; /* If the new part is part Z, then finish * with the current entry. */ if (id == 'Z') { alp_pp->current_entry->size = alp_pp->current_offset - alp_pp->current_entry->offset; /* Create the MD5 digest. */ apr_md5_final(alp_pp->current_entry->md5_digest, alp_pp->current_entry->md5_context); /* Event ENTRY_END. */ if (alp_pp->callback != NULL) { if (alp_pp->callback(alp_pp, ALP2_EVENT_ENTRY_END) == 0) { alp_pp->done = 1; } } /* We are about to destroy our only reference to the per-entry * memory pool, but that is all right since we've passed all * responsibility for the entry to the higher-level handler. */ alp_pp->current_entry = NULL; } } if (id != 'Z') { /* Create new entry if necessary. */ if (alp_pp->current_entry == NULL) { apr_pool_t *new_pool = NULL; /* Create a per-entry pool directly from the main memory pool. */ apr_pool_create(&new_pool, apr_pool_parent_get(alp_pp->mp)); alp_pp->current_entry = apr_pcalloc(new_pool, sizeof(alp2_pp_entry_t)); alp_pp->current_entry->mp = new_pool; alp_pp->current_entry->offset = alp_pp->line_offset; alp_pp->current_entry->boundary = apr_pstrdup(new_pool, alp_pp->boundary); alp_pp->boundary = NULL; alp_pp->current_entry->parts = apr_array_make(alp_pp->current_entry->mp, 16, sizeof(alp2_pp_part_t *)); /* Initialise the MD5 context. */ alp_pp->current_entry->md5_context = apr_pcalloc(alp_pp->current_entry->mp, sizeof(apr_md5_ctx_t)); apr_md5_init(alp_pp->current_entry->md5_context); /* Start calculating the has with the first line. */ apr_md5_update(alp_pp->current_entry->md5_context, &alp_pp->line_buf[0], alp_pp->line_pos - 1); /* Event ENTRY_START. */ if (alp_pp->callback != NULL) { if (alp_pp->callback(alp_pp, ALP2_EVENT_ENTRY_START) == 0) { alp_pp->done = 1; } } } /* Create new part, but only if we are not * dealing with an entry terminator. */ alp_pp->current_part = apr_pcalloc(alp_pp->current_entry->mp, sizeof(alp2_pp_part_t)); alp_pp->current_part->id = id; alp_pp->current_part->offset = alp_pp->current_offset; /* Event PART_START. */ if (alp_pp->callback != NULL) { if (alp_pp->callback(alp_pp, ALP2_EVENT_PART_START) == 0) { alp_pp->done = 1; } } } } else { /* The line does not contain a boundary, * so process it as part data. */ alp2_pp_process_part_data(alp_pp); } } else { /* We have a chunk of data that is not a line, which * probably means that our buffer was not big enough, either * because the line (is a line and it) was too big, or because * we are processing binary data. Ideally the latter. */ alp2_pp_process_part_data(alp_pp); } /* Reset the line buffer. */ alp_pp->line_pos = 0; alp_pp->line_has_start = 1; alp_pp->line_offset = alp_pp->current_offset; } } if (alp_pp->done) { return ALP2_DONE; } else { return ALP2_NEED_DATA; } }
int ap_open_logs(apr_pool_t *pconf, apr_pool_t *p /* plog */, apr_pool_t *ptemp, server_rec *s_main) { apr_pool_t *stderr_p; server_rec *virt, *q; int replace_stderr; /* Register to throw away the read_handles list when we * cleanup plog. Upon fork() for the apache children, * this read_handles list is closed so only the parent * can relaunch a lost log child. These read handles * are always closed on exec. * We won't care what happens to our stderr log child * between log phases, so we don't mind losing stderr's * read_handle a little bit early. */ apr_pool_cleanup_register(p, NULL, clear_handle_list, apr_pool_cleanup_null); /* HERE we need a stdout log that outlives plog. * We *presume* the parent of plog is a process * or global pool which spans server restarts. * Create our stderr_pool as a child of the plog's * parent pool. */ apr_pool_create(&stderr_p, apr_pool_parent_get(p)); apr_pool_tag(stderr_p, "stderr_pool"); if (open_error_log(s_main, 1, stderr_p) != OK) { return DONE; } replace_stderr = 1; if (s_main->error_log) { apr_status_t rv; /* Replace existing stderr with new log. */ apr_file_flush(s_main->error_log); rv = apr_file_dup2(stderr_log, s_main->error_log, stderr_p); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_CRIT, rv, s_main, "unable to replace stderr with error_log"); } else { /* We are done with stderr_pool, close it, killing * the previous generation's stderr logger */ if (stderr_pool) apr_pool_destroy(stderr_pool); stderr_pool = stderr_p; replace_stderr = 0; /* * Now that we have dup'ed s_main->error_log to stderr_log * close it and set s_main->error_log to stderr_log. This avoids * this fd being inherited by the next piped logger who would * keep open the writing end of the pipe that this one uses * as stdin. This in turn would prevent the piped logger from * exiting. */ apr_file_close(s_main->error_log); s_main->error_log = stderr_log; } } /* note that stderr may still need to be replaced with something * because it points to the old error log, or back to the tty * of the submitter. * XXX: This is BS - /dev/null is non-portable */ if (replace_stderr && freopen("/dev/null", "w", stderr) == NULL) { ap_log_error(APLOG_MARK, APLOG_CRIT, errno, s_main, "unable to replace stderr with /dev/null"); } for (virt = s_main->next; virt; virt = virt->next) { if (virt->error_fname) { for (q=s_main; q != virt; q = q->next) { if (q->error_fname != NULL && strcmp(q->error_fname, virt->error_fname) == 0) { break; } } if (q == virt) { if (open_error_log(virt, 0, p) != OK) { return DONE; } } else { virt->error_log = q->error_log; } } else { virt->error_log = s_main->error_log; } } return OK; }
APR_DECLARE(apr_status_t) apr_dbd_init(apr_pool_t *pool) { apr_status_t ret = APR_SUCCESS; apr_pool_t *parent; if (apr_atomic_inc32(&initialised)) { apr_atomic_set32(&initialised, 1); /* prevent wrap-around */ while (apr_atomic_read32(&in_init)) /* wait until we get fully inited */ ; return APR_SUCCESS; } /* Top level pool scope, need process-scope lifetime */ for (parent = pool; parent; parent = apr_pool_parent_get(pool)) pool = parent; #if APR_HAVE_MODULAR_DSO /* deprecate in 2.0 - permit implicit initialization */ apu_dso_init(pool); #endif drivers = apr_hash_make(pool); #if APR_HAS_THREADS ret = apr_thread_mutex_create(&mutex, APR_THREAD_MUTEX_DEFAULT, pool); /* This already registers a pool cleanup */ #endif #if !APR_HAVE_MODULAR_DSO /* Load statically-linked drivers: */ #if APU_HAVE_MYSQL DRIVER_LOAD("mysql", apr_dbd_mysql_driver, pool); #endif #if APU_HAVE_PGSQL DRIVER_LOAD("pgsql", apr_dbd_pgsql_driver, pool); #endif #if APU_HAVE_SQLITE3 DRIVER_LOAD("sqlite3", apr_dbd_sqlite3_driver, pool); #endif #if APU_HAVE_SQLITE2 DRIVER_LOAD("sqlite2", apr_dbd_sqlite2_driver, pool); #endif #if APU_HAVE_ORACLE DRIVER_LOAD("oracle", apr_dbd_oracle_driver, pool); #endif #if APU_HAVE_FREETDS DRIVER_LOAD("freetds", apr_dbd_freetds_driver, pool); #endif #if APU_HAVE_ODBC DRIVER_LOAD("odbc", apr_dbd_odbc_driver, pool); #endif #if APU_HAVE_SOME_OTHER_BACKEND DRIVER_LOAD("firebird", apr_dbd_other_driver, pool); #endif #endif /* APR_HAVE_MODULAR_DSO */ apr_pool_cleanup_register(pool, NULL, apr_dbd_term, apr_pool_cleanup_null); apr_atomic_dec32(&in_init); return ret; }