void *merge_php_config(apr_pool_t *p, void *base_conf, void *new_conf) { php_conf_rec *d = base_conf, *e = new_conf, *n = NULL; php_dir_entry *pe; php_dir_entry *data; char *str; uint str_len; ulong num_index; n = create_php_config(p, "merge_php_config"); zend_hash_copy(&n->config, &e->config, NULL, NULL, sizeof(php_dir_entry)); phpapdebug((stderr, "Merge dir (%p)+(%p)=(%p)\n", base_conf, new_conf, n)); for (zend_hash_internal_pointer_reset(&d->config); zend_hash_get_current_key_ex(&d->config, &str, &str_len, &num_index, 0, NULL) == HASH_KEY_IS_STRING; zend_hash_move_forward(&d->config)) { pe = NULL; zend_hash_get_current_data(&d->config, (void **) &data); if (zend_hash_find(&n->config, str, str_len, (void **) &pe) == SUCCESS) { if (pe->status >= data->status) continue; } zend_hash_update(&n->config, str, str_len, data, sizeof(*data), NULL); phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", str, data->status, pe?pe->status:-1)); } return n; }
void apply_config(void *dummy) { php_conf_rec *d = dummy; char *str; uint str_len; php_dir_entry *data; for (zend_hash_internal_pointer_reset(&d->config); zend_hash_get_current_key(&d->config, &str, &str_len, NULL) == HASH_KEY_IS_STRING; zend_hash_move_forward(&d->config)) { zend_hash_get_current_data(&d->config, (void **) &data); phpapdebug((stderr, "APPLYING (%s)(%s)\n", str, data->value)); if (zend_alter_ini_entry(str, str_len, data->value, data->value_len, data->status, data->htaccess?PHP_INI_STAGE_HTACCESS:PHP_INI_STAGE_ACTIVATE) == FAILURE) { phpapdebug((stderr, "..FAILED\n")); } } }
void *create_php_config(apr_pool_t *p, char *dummy) { php_conf_rec *newx = (php_conf_rec *) apr_pcalloc(p, sizeof(*newx)); phpapdebug((stderr, "Creating new config (%p) for %s\n", newx, dummy)); zend_hash_init(&newx->config, 0, NULL, NULL, 1); apr_pool_cleanup_register(p, newx, destroy_php_config, apr_pool_cleanup_null); return (void *) newx; }
static apr_status_t destroy_php_config(void *data) { php_conf_rec *d = data; phpapdebug((stderr, "Destroying config %p\n", data)); zend_hash_destroy(&d->config); return APR_SUCCESS; }
static zend_bool should_overwrite_per_dir_entry(HashTable *target_ht, php_dir_entry *new_per_dir_entry, zend_hash_key *hash_key, void *pData) { php_dir_entry *orig_per_dir_entry; if (zend_hash_find(target_ht, hash_key->arKey, hash_key->nKeyLength, (void **) &orig_per_dir_entry)==FAILURE) { return 1; /* does not exist in dest, copy from source */ } if (new_per_dir_entry->status >= orig_per_dir_entry->status) { /* use new entry */ phpapdebug((stderr, "ADDING/OVERWRITING %s (%d vs. %d)\n", hash_key->arKey, new_per_dir_entry->status, orig_per_dir_entry->status)); return 1; } else { return 0; } }
static const char *real_value_hnd(cmd_parms *cmd, void *dummy, const char *name, const char *value, int status) { php_conf_rec *d = dummy; php_dir_entry e; phpapdebug((stderr, "Getting %s=%s for %p (%d)\n", name, value, dummy, zend_hash_num_elements(&d->config))); if (!strncasecmp(value, "none", sizeof("none"))) { value = ""; } e.value = apr_pstrdup(cmd->pool, value); e.value_len = strlen(value); e.status = status; e.htaccess = ((cmd->override & (RSRC_CONF|ACCESS_CONF)) == 0); zend_hash_update(&d->config, (char *) name, strlen(name) + 1, &e, sizeof(e), NULL); return NULL; }