15 #include <apr_buckets.h>
16 #include <apr_strings.h>
20 #define AFW_IMPLEMENTATION_ID "file"
26 static const afw_utf8_t impl_factory_description =
32 &impl_afw_adaptor_factory_inf,
34 &impl_factory_description
50 rv = apr_filepath_merge(
51 &full_path_z, NULL, path_z,
52 APR_FILEPATH_TRUENAME,
54 if (rv != APR_SUCCESS) {
56 "Unresolvable path %s", path_z);
58 len = strlen(full_path_z);
59 if (len > 0 && full_path_z[len - 1] !=
'/') {
89 in = fopen(file_path_z,
"r");
92 "Error opening %s errno %d", file_path_z, errno);
99 rv = apr_stat(&finfo, file_path_z, APR_FINFO_SIZE,
101 if (rv != APR_SUCCESS) {
103 "apr_stat() failed.", xctx);
105 file_size = (size_t)finfo.size;
111 to_memory->size = fread(buff, 1, file_size, in);
112 to_memory->ptr = buff;
113 if (to_memory->size < 1) {
159 for (i = file_path->s, o = file_path_z, count = file_path->len;
164 if (*o ==
'\\') *o =
'/';
165 if (*o ==
'/') last_slash = o;
174 case afw_file_mode_write:
181 case afw_file_mode_write_new:
182 rv = apr_file_open(&f, file_path_z, APR_FOPEN_READ,
183 APR_FPROT_OS_DEFAULT, apr_p);
184 if (rv == APR_SUCCESS) {
187 "File %s already exists.", file_path_z);
194 step_z =
"apr_dir_make_recursive()";
195 rv = apr_dir_make_recursive(file_path_z,
196 APR_FPROT_OS_DEFAULT, apr_p);
197 if (rv != APR_SUCCESS)
goto error_apr;
203 case afw_file_mode_write_existing:
212 step_z =
"apr_file_open()";
213 rv = apr_file_open(&f, file_path_z, APR_FOPEN_WRITE + APR_FOPEN_CREATE,
214 APR_FPROT_OS_DEFAULT, apr_p);
215 if (rv != APR_SUCCESS)
goto error_apr;
218 step_z =
"apr_file_write()";
219 count = from_memory->size;
220 rv = apr_file_write(f, from_memory->ptr, &count);
221 if (rv != APR_SUCCESS)
goto error_apr;
224 step_z =
"apr_file_trunc()";
225 rv = apr_file_trunc(f, from_memory->size);
226 if (rv != APR_SUCCESS)
goto error_apr;
229 step_z =
"apr_file_close()";
230 rv = apr_file_close(f);
231 if (rv != APR_SUCCESS)
goto error_apr;
238 "Error writing file %s - %s",
239 file_path_z, step_z);
253 "Error deleting %s.", file_path_z);
263 return &impl_adaptor_factory;
271 impl_afw_adaptor_factory_create_adaptor_cede_p (
297 &impl_afw_adaptor_inf,
299 properties, p, xctx);
305 &afw_s_contentType, p, xctx);
308 if (!self->content_type)
311 &afw_s_contentType, xctx);
316 properties, &afw_s_filenameSuffix, p, xctx);
317 if (!self->filename_suffix) {
318 self->filename_suffix = &afw_s_a_empty_string;
323 properties, &afw_s_root, adaptor->source_location,
324 afw_compile_type_hybrid, p, xctx);
345 &afw_s_isDevelopmentInput, xctx);
348 &afw_s__AdaptiveCollection_,
true,
true, xctx);
350 &afw_s__AdaptiveDataTypeGenerate_,
true,
true, xctx);
352 &afw_s__AdaptiveManifest_,
true,
true, xctx);
354 &afw_s__AdaptiveFunctionGenerate_,
true,
true, xctx);
356 &afw_s__AdaptiveObjectType_,
true,
true, xctx);
358 &afw_s__AdaptiveValueMeta_,
true,
true, xctx);
391 session->pub.inf = &impl_afw_adaptor_session_inf;
393 session->pub.p = xctx->p;
394 session->adaptor =
self;
397 session->journal.inf = afw_file_internal_get_journal_inf();
467 const char *dirname_z;
487 if (APR_STATUS_IS_ENOENT(rv)) {
488 callback(NULL, context, xctx);
493 if (rv != APR_SUCCESS) {
502 rv = apr_dir_read(&finfo, APR_FINFO_SIZE + APR_FINFO_NAME, dir);
503 if (rv == APR_ENOENT || rv == 720018)
break;
505 if (rv != APR_SUCCESS) {
506 apr_strerror(rv, &err[0], 100);
512 if (*(finfo.name) ==
'.') {
517 len = strlen(finfo.name);
518 if (adaptor->filename_suffix) {
519 if (len <= adaptor->filename_suffix->len ||
520 memcmp(finfo.name + (len - adaptor->filename_suffix->len),
521 adaptor->filename_suffix->s,
522 adaptor->filename_suffix->len) != 0)
526 len -= adaptor->filename_suffix->len;
549 adaptor->content_type, raw, full_path, &adaptor->pub.adaptor_id,
550 object_type_id, object_id,
true, obj_p, xctx);
557 if (callback(obj, context, xctx)) {
569 rv = apr_dir_close(dir);
570 if (rv != APR_SUCCESS) {
576 callback(NULL, context, xctx);
606 full_path = impl_get_full_path(adaptor, object_type_id, object_id,
615 adaptor->content_type, raw, full_path,
616 &adaptor->pub.adaptor_id, object_type_id, object_id,
620 callback(
object, context, xctx);
643 object_id = (suggested_object_id)
644 ? suggested_object_id
647 full_path = impl_get_full_path(adaptor, object_type_id, object_id,
679 if (!object_id || !object_type_id) {
681 "Missing object id or object_type.", xctx);
690 " objects are read-only", xctx);
693 full_path = impl_get_full_path(adaptor, object_type_id, object_id,
699 adaptor->content_type, raw, full_path,
700 &adaptor->pub.adaptor_id,
701 object_type_id, object_id,
false, xctx->p, xctx);
705 entry,
object, xctx);
734 if (!object_id || !object_type_id) {
736 "Updated object missing id or object_type.", xctx);
739 full_path = impl_get_full_path(adaptor, object_type_id,
740 object_id, xctx->p, xctx);
767 full_path = impl_get_full_path(adaptor, object_type_id, object_id,
790 impl_afw_adaptor_session_get_journal_interface(
833 impl_afw_adaptor_session_get_object_type_cache_interface(
Interface afw_interface implementation declares.
Interface afw_interface implementation declares.
AFW_DEFINE(const afw_object_t *)
Interface afw_interface implementation declares.
Adaptive Framework Core Internal.
const afw_object_t * impl_afw_adaptor_get_additional_metrics(const afw_adaptor_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
void impl_afw_adaptor_destroy(const afw_adaptor_t *instance, afw_xctx_t *xctx)
const afw_adaptor_session_t * impl_afw_adaptor_create_adaptor_session(const afw_adaptor_t *instance, afw_xctx_t *xctx)
afw_adaptor_impl_throw_property_invalid(const afw_adaptor_t *adaptor, const afw_utf8_t *property_name, afw_xctx_t *xctx)
Developers should call this for configuration property errors.
afw_adaptor_impl_create_cede_p(const afw_adaptor_inf_t *inf, afw_size_t instance_size, const afw_object_t *properties, const afw_pool_t *p, afw_xctx_t *xctx)
Developers should call this in all create functions for afw_adaptor.
afw_adaptor_impl_set_supported_core_object_type(const afw_adaptor_t *adaptor, const afw_utf8_t *object_type_id, afw_boolean_t allow_entity, afw_boolean_t allow_write, afw_xctx_t *xctx)
Indicates support of a core object type.
void impl_afw_adaptor_session_modify_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_adaptor_modify_entry_t *const *entry, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
void impl_afw_adaptor_session_replace_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_object_t *replacement_object, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
void impl_afw_adaptor_session_delete_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
void impl_afw_adaptor_session_retrieve_objects(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_query_criteria_t *criteria, void *context, afw_object_cb_t callback, const afw_object_t *adaptor_type_specific, const afw_pool_t *p, afw_xctx_t *xctx)
const afw_adaptor_transaction_t * impl_afw_adaptor_session_begin_transaction(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
void impl_afw_adaptor_session_destroy(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
const afw_adaptor_impl_index_t * impl_afw_adaptor_session_get_index_interface(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
const afw_utf8_t * impl_afw_adaptor_session_add_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *suggested_object_id, const afw_object_t *object, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
void impl_afw_adaptor_session_get_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, void *context, afw_object_cb_t callback, const afw_object_t *adaptor_type_specific, const afw_pool_t *p, afw_xctx_t *xctx)
const afw_adaptor_key_value_t * impl_afw_adaptor_session_get_key_value_interface(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
afw_adaptor_modify_entries_apply_to_unnormalized_object(const afw_adaptor_modify_entry_t *const *entries, const afw_object_t *object, afw_xctx_t *xctx)
Apply modify entries to an unnormalized object.
#define afw_value_is_string(A_VALUE)
Macro to determine if value is evaluated string.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
#define AFW_UTF8_Z_LEN
String is NUL (0) terminate.
afw_boolean_t(* afw_object_cb_t)(const afw_object_t *object, void *context, afw_xctx_t *xctx)
Typedef for afw_adaptor_session_object callback.
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
unsigned char afw_byte_t
A byte of memory (unsigned).
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
apr_size_t afw_size_t
size_t.
#define afw_content_type_raw_to_object(instance, raw, source_location, adaptor_id, object_type_id, object_id, cede_p, p, xctx)
Call method raw_to_object of interface afw_content_type.
#define afw_content_type_object_to_raw(instance, object, options, p, xctx)
Convert object to the raw in specified pool.
const afw_content_type_t * afw_environment_get_content_type(const afw_utf8_t *type, afw_xctx_t *xctx)
Get the afw_content_type struct associated with a content type.
#define AFW_FINALLY
Always executed regardless of error.
#define AFW_THROW_ERROR_RV_Z(code, rv_source_id, rv, message_z, xctx)
Macro used to set error and rv in xctx and throw it.
#define AFW_ENDTRY
Ends an AFW try block.
#define AFW_TRY
Begin an AFW TRY block.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_THROW_ERROR_RV_FZ(code, rv_source_id, rv, xctx, format_z,...)
Macro used to set error and rv in xctx and throw it.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
afw_file_insure_full_path(const afw_utf8_t *path, const afw_pool_t *p, afw_xctx_t *xctx)
Return full file path.
afw_file_from_memory(const afw_utf8_t *file_path, const afw_memory_t *from_memory, afw_file_mode_t mode, afw_xctx_t *xctx)
Write a file from a memory.
afw_file_to_memory(const afw_utf8_t *file_path, apr_size_t file_size, const afw_pool_t *p, afw_xctx_t *xctx)
Read a file into a memory in a specifed pool.
afw_file_adaptor_create_cede_p(const afw_object_t *properties, const afw_pool_t *p, afw_xctx_t *xctx)
Create a file adaptor.
void afw_file_delete(const afw_utf8_t *file_path, afw_xctx_t *xctx)
Delete file.
enum afw_file_mode_e afw_file_mode_t
afw_file_adaptor_factory_get()
Get the factory for file adaptor.
#define afw_object_release(instance, xctx)
Call method release of interface afw_object.
afw_object_options_essential_with_whitespace
Object processing options - metaLimited + whitespace.
afw_object_old_get_property_as_utf8(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_pool_t *p, afw_xctx_t *xctx)
Get an object's property value as a string in specified pool.
#define AFW_OBJECT_Q_OBJECT_TYPE_ID_JOURNAL_ENTRY
Quoted object type id for Journal Entry object.
afw_object_old_get_property_as_boolean_deprecated(const afw_object_t *instance, const afw_utf8_t *property_name, afw_xctx_t *xctx)
Get an object's property value as a boolean.
afw_object_get_property_compile_and_evaluate_as(const afw_object_t *instance, const afw_utf8_t *property_name, const afw_utf8_t *source_location, afw_compile_type_t compile_type, const afw_pool_t *p, afw_xctx_t *xctx)
Compile and evaluate a property value using specified compile type.
#define AFW_OBJECT_S_OBJECT_TYPE_ID_JOURNAL_ENTRY
String object type id for Journal Entry object.
#define afw_pool_malloc(instance, size, xctx)
Call method malloc of interface afw_pool.
#define afw_pool_get_apr_pool(instance)
Call method get_apr_pool of interface afw_pool.
#define afw_pool_release(instance, xctx)
Call method release of interface afw_pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
const afw_pool_t * afw_pool_create(const afw_pool_t *parent, afw_xctx_t *xctx)
Create a new pool.
afw_query_criteria_test_object(const afw_object_t *obj, const afw_query_criteria_t *criteria, const afw_pool_t *p, afw_xctx_t *xctx)
Test object against query criteria.
#define afw_utf8_create_copy(s, len, p, xctx)
Make a utf-8 sting from chars in pool specified.
afw_boolean_t afw_utf8_equal(const afw_utf8_t *s1, const afw_utf8_t *s2)
Check to see if a string equals another string.
const afw_utf8_z_t * afw_utf8_z_printf(const afw_pool_t *p, afw_xctx_t *xctx, const afw_utf8_z_t *format_z,...)
const afw_utf8_z_t * afw_utf8_to_utf8_z(const afw_utf8_t *string, const afw_pool_t *p, afw_xctx_t *xctx)
Convert utf8 to utf8_z in specified pool.
afw_utf8_printf(const afw_pool_t *p, afw_xctx_t *xctx, const afw_utf8_z_t *format,...)
Create a utf-8 string using a c format string in specified pool.
#define afw_utf8_create(s, len, p, xctx)
Create utf-8 string without copy unless necessary in pool specified.
afw_uuid_create_utf8(const afw_pool_t *p, afw_xctx_t *xctx)
Create a UUID as a standard format UUID utf-8 string.
#define afw_xctx_calloc(size, xctx)
Macro to allocate cleared memory in xctx's pool.
#define afw_xctx_calloc_type(type, xctx)
Macro to allocate cleared memory to hold type in xctx's pool.
Interface afw_adaptor_factory public struct.
Interface afw_adaptor_impl_index public struct.
Internal request info used by afw_adaptor_impl*() functions.
Interface afw_adaptor_journal public struct.
Interface afw_adaptor_key_value public struct.
Interface afw_adaptor_object_type_cache public struct.
Interface afw_adaptor public struct.
Interface afw_adaptor_session public struct.
Interface afw_adaptor_transaction public struct.
Struct for memory pointer and size.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Interface afw_value public struct.
struct for data type string values.
Interface afw_xctx public struct.