コード例 #1
0
static dav_error *
dav_rawx_deliver_SPECIAL(const dav_resource *resource, ap_filter_t *output)
{
	(void) output;
	dav_error *e = NULL;
	const request_rec *r = resource->info->request;
	GHashTable *comp_opt = NULL;
	struct chunk_textinfo_s *chunk = NULL;
	char *path = NULL;
	apr_pool_t *p = resource->pool;

	/* Load request informations */
	e = _load_request_info(resource, &path);
	if (NULL != e) {
		DAV_ERROR_REQ(r, 0, "Failed to load request informations: %s", e->desc);
		goto end_deliver;
	}

	comp_opt = g_hash_table_new_full( g_str_hash, g_str_equal, g_free, g_free);
	apr_pool_cleanup_register(p, comp_opt, apr_hash_table_clean, apr_pool_cleanup_null);
	chunk = apr_palloc(p, sizeof(struct chunk_textinfo_s));

	/* Load in place informations (sys-metadata & metadatacompress) */
	e = _load_in_place_chunk_info(resource, path, chunk, comp_opt);
	if (NULL != e) {
		DAV_ERROR_REQ(r, 0, "Failed to load in place chunk information: %s", e->desc);
		goto end_deliver;
	}

	DAV_ERROR_REQ(r, 0, "Failed to update chunk storage: PAYMENT REQUIRED"
			" to compress data (we accept bitcoins)");
	dav_rawx_server_conf *conf = resource_get_server_config(resource);
	e = server_create_and_stat_error(conf, p, HTTP_PAYMENT_REQUIRED,
			0, "Pay more to manage compression");

end_deliver:
	/* stats inc */
	return e;
}
コード例 #2
0
static dav_error *
dav_rawx_deliver_SPECIAL(const dav_resource *resource, ap_filter_t *output)
{
	(void) output;
	dav_error *e = NULL;
	struct storage_policy_s *sp = NULL;
	const struct data_treatments_s *dt = NULL;
	const request_rec *r = resource->info->request;
	GHashTable *comp_opt = NULL;
	struct content_textinfo_s *content = NULL;
	struct chunk_textinfo_s *chunk = NULL;
	char *path = NULL;
	apr_pool_t *p = resource->pool;
	
	/* Load request informations */
	e = _load_request_info(resource, &path, &sp);
	if (NULL != e) {
		DAV_ERROR_REQ(r, 0, "Failed to load request informations: %s", e->desc);
		goto end_deliver;
	}

	if(!sp) {
		DAV_DEBUG_REQ(r, 0, "Storage policy not initialized with value found in header, don't do anything");
		goto end_deliver;
	}

	dt = storage_policy_get_data_treatments(sp);
	if(!dt)
		DAV_DEBUG_REQ(r, 0, "Data treatments not defined for this policy");

	comp_opt = g_hash_table_new_full( g_str_hash, g_str_equal, g_free, g_free);
	apr_pool_cleanup_register(p, comp_opt, apr_hash_table_clean, apr_pool_cleanup_null);
	chunk = apr_palloc(p, sizeof(struct chunk_textinfo_s));
	content = apr_palloc(p, sizeof(struct content_textinfo_s));

	/* Load in place informations (sys-metadata & metadatacompress) */
	e = _load_in_place_chunk_info(resource, path, content, chunk, &comp_opt);
	if (NULL != e) {
		DAV_ERROR_REQ(r, 0, "Failed to load in place chunk information: %s", e->desc);
		goto end_deliver;
	}

	DAV_DEBUG_REQ(r, 0, "In place chunk info loaded, compression status : %s", (gchar*)g_hash_table_lookup(comp_opt, NS_COMPRESSION_OPTION));

	/* check chunk not in required state */
	if (APR_SUCCESS != _is_storage_policy_already_applied(dt, comp_opt)) {
		DAV_DEBUG_REQ(r, 0, "Storage policy not already applied, apply it!");
		/* operate the data treatments */
		e = _update_chunk_storage(resource, path, dt, comp_opt);
		if (NULL != e) {
			DAV_ERROR_REQ(r, 0, "Failed to update chunk storage: %s", e->desc);
			goto end_deliver;
		}
		DAV_DEBUG_REQ(r, 0, "Chunk storage updated");
	} else {
		DAV_DEBUG_REQ(r, 0, "Storage policy already applied, don't do anything!");
	}


	/* ensure sys-metadata header is valid */
	e = _ensure_sys_metadata(resource, path, storage_policy_get_name(sp), content);
	if (NULL != e) {
		DAV_ERROR_REQ(r, 0, "Failed to ensure sys-metadata, storage-policy possibly not correctly present in xattr: %s", e->desc);
		goto end_deliver;
	}

end_deliver:

	/* stats inc */

	return e;
}