Adaptive Framework  0.9.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
afw_file.c
Go to the documentation of this file.
1 // See the 'COPYING' file in the project root for licensing information.
2 /*
3  * Adaptive framework file support
4  *
5  * Copyright (c) 2010-2023 Clemson University
6  *
7  */
8 
14 #include "afw_internal.h"
15 #include <apr_buckets.h>
16 #include <apr_strings.h>
17 
18 
19 /* Declares and rti/inf defines for interface afw_adaptor_factory */
20 #define AFW_IMPLEMENTATION_ID "file"
24 
25 
26 static const afw_utf8_t impl_factory_description =
27 AFW_UTF8_LITERAL("Adaptor type for accessing objects contained in files.");
28 
29 /* File adaptor factory instance. */
30 static const afw_adaptor_factory_t impl_adaptor_factory =
31 {
32  &impl_afw_adaptor_factory_inf,
34  &impl_factory_description
35 };
36 
37 
38 /* Return full file path. */
39 AFW_DEFINE(const afw_utf8_t *)
41  const afw_pool_t *p, afw_xctx_t *xctx)
42 {
43  const afw_utf8_t *full_path;
44  const char *path_z;
45  char *full_path_z;
46  size_t len;
47  apr_status_t rv;
48 
49  path_z = afw_utf8_to_utf8_z(path, p, xctx);
50  rv = apr_filepath_merge(
51  &full_path_z, NULL, path_z,
52  APR_FILEPATH_TRUENAME,
54  if (rv != APR_SUCCESS) {
55  AFW_THROW_ERROR_RV_FZ(general, apr, rv, xctx,
56  "Unresolvable path %s", path_z);
57  }
58  len = strlen(full_path_z);
59  if (len > 0 && full_path_z[len - 1] != '/') {
60  full_path = afw_utf8_printf(p, xctx, "%s/", full_path_z);
61  }
62  else {
63  full_path = afw_utf8_create_copy(full_path_z, AFW_UTF8_Z_LEN, p, xctx);
64  }
65  return full_path;
66 }
67 
68 
69 /* Read a file into memory in a specifed pool. */
70 AFW_DEFINE(const afw_memory_t *)
72  const afw_utf8_t * file_path,
73  apr_size_t file_size,
74  const afw_pool_t *p,
75  afw_xctx_t *xctx)
76 {
77  afw_memory_t *to_memory;
78  afw_byte_t *buff;
79  FILE *in;
80  apr_status_t rv;
81  apr_finfo_t finfo;
82  const afw_utf8_z_t *file_path_z;
83 
84  /* Allocate to_memory struct. */
85  to_memory = afw_pool_calloc_type(p, afw_memory_t, xctx);
86 
87  /* Open file. */
88  file_path_z = afw_utf8_to_utf8_z(file_path, p, xctx);
89  in = fopen(file_path_z, "r");
90  if (!in) {
91  AFW_THROW_ERROR_FZ(not_found, xctx,
92  "Error opening %s errno %d", file_path_z, errno);
93  }
94 
95  AFW_TRY {
96 
97  /* Get size of file if not supplied. */
98  if (file_size == 0) {
99  rv = apr_stat(&finfo, file_path_z, APR_FINFO_SIZE,
101  if (rv != APR_SUCCESS) {
102  AFW_THROW_ERROR_RV_Z(general, apr, rv,
103  "apr_stat() failed.", xctx);
104  }
105  file_size = (size_t)finfo.size;
106  }
107  /* Create a buffer big enough for contents of file. */
108  buff = afw_pool_malloc(p, file_size, xctx);
109 
110  /* Read file into buffer. */
111  to_memory->size = fread(buff, 1, file_size, in);
112  to_memory->ptr = buff;
113  if (to_memory->size < 1) {
114  AFW_THROW_ERROR_FZ(general, xctx,
115  "Error reading %" AFW_UTF8_FMT ".",
116  AFW_UTF8_FMT_ARG(file_path));
117  }
118 
119  }
120 
121  AFW_FINALLY{
122  /* Close input file. */
123  fclose(in);
124  }
125 
126  AFW_ENDTRY;
127 
128  /* Return result. */
129  return to_memory;
130 
131 }
132 
133 
134 /* Write a file from memory. */
135 AFW_DEFINE(void)
137  const afw_utf8_t * file_path,
138  const afw_memory_t * from_memory,
139  afw_file_mode_t mode,
140  afw_xctx_t *xctx)
141 {
142  apr_pool_t *apr_p = afw_pool_get_apr_pool(xctx->p);
143  apr_file_t *f;
144  afw_utf8_z_t *file_path_z;
145  apr_status_t rv;
146  const afw_utf8_z_t *step_z;
147  const afw_utf8_octet_t *i;
148  afw_utf8_octet_t *o;
150  afw_utf8_octet_t *last_slash;
151  afw_size_t count;
152 
153  /*
154  * Make afw_u8_z copy of name with '\' changed to '/'. Remember location
155  * of last slash.
156  */
157  file_path_z = afw_xctx_calloc(file_path->len + 1, xctx);
158  last_slash = NULL;
159  for (i = file_path->s, o = file_path_z, count = file_path->len;
160  count > 0;
161  i++, o++, count--)
162  {
163  *o = *i;
164  if (*o == '\\') *o = '/';
165  if (*o == '/') last_slash = o;
166  }
167  *o = 0;
168 
169 
170  /* Process based on file mode. */
171  switch (mode) {
172 
173  /* Mode write ok. */
174  case afw_file_mode_write:
175  break;
176 
177  /*
178  * For mode write_new, check that file does not already exist and that
179  * the directory stucture exists.
180  */
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) {
185  apr_file_close(f);
186  AFW_THROW_ERROR_FZ(general, xctx,
187  "File %s already exists.", file_path_z);
188  }
189  /* If there is a '/' in path, make sure all of the directories exist */
190  if (last_slash) {
191  o = last_slash + 1;
192  c = *o;
193  *o = 0;
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;
198  *o = c;
199  }
200  break;
201 
202  /* Mode write_existing ok. */
203  case afw_file_mode_write_existing:
204  break;
205 
206  /* Other modes are invalid. */
207  default:
208  AFW_THROW_ERROR_FZ(general, xctx, "Invalid mode %d.", mode);
209  };
210 
211  /* Open file for write. */
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;
216 
217  /* Write memory to file. */
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;
222 
223  /* Truncate file to length written. */
224  step_z = "apr_file_trunc()";
225  rv = apr_file_trunc(f, from_memory->size);
226  if (rv != APR_SUCCESS) goto error_apr;
227 
228  /* Close file. */
229  step_z = "apr_file_close()";
230  rv = apr_file_close(f);
231  if (rv != APR_SUCCESS) goto error_apr;
232 
233  /* Return. */
234  return;
235 
236 error_apr:
237  AFW_THROW_ERROR_RV_FZ(general, apr, rv, xctx,
238  "Error writing file %s - %s",
239  file_path_z, step_z);
240 }
241 
242 
243 /* Delete file. */
245  const afw_utf8_t * file_path,
246  afw_xctx_t *xctx)
247 {
248  const afw_utf8_z_t *file_path_z;
249 
250  file_path_z = afw_utf8_to_utf8_z(file_path, xctx->p, xctx);
251  if (apr_file_remove(file_path_z, afw_pool_get_apr_pool(xctx->p)) < 0) {
252  AFW_THROW_ERROR_FZ(not_found, xctx,
253  "Error deleting %s.", file_path_z);
254  }
255 
256 }
257 
258 
259 /* Get the factory for file adaptor .*/
262 {
263  return &impl_adaptor_factory;
264 }
265 
266 
267 /*
268  * Implementation of method create_adaptor_cede_p of interface afw_adaptor_factory.
269  */
270 const afw_adaptor_t *
271 impl_afw_adaptor_factory_create_adaptor_cede_p (
272  const afw_adaptor_factory_t * instance,
273  const afw_object_t * properties,
274  const afw_pool_t * p,
275  afw_xctx_t *xctx)
276 {
277  /* Create file adaptor. */
278  return afw_file_adaptor_create_cede_p(properties, p, xctx);
279 }
280 
281 
282 
283 /* Create function for file adaptor. */
284 AFW_DEFINE(const afw_adaptor_t *)
286  const afw_object_t *properties,
287  const afw_pool_t *p, afw_xctx_t *xctx)
288 {
290  afw_adaptor_t *adaptor;
291  const afw_utf8_t *content_type;
292  const afw_value_t *value;
293  afw_boolean_t b;
294 
295  /* Create adaptor and process common properties. */
297  &impl_afw_adaptor_inf,
299  properties, p, xctx);
300  self = (afw_file_internal_adaptor_t *)adaptor;
301  p = self->pub.p;
302 
303  /* Get content_type parameters. */
304  content_type = afw_object_old_get_property_as_utf8(properties,
305  &afw_s_contentType, p, xctx);
306  self->content_type = afw_environment_get_content_type(content_type,
307  xctx);
308  if (!self->content_type)
309  {
311  &afw_s_contentType, xctx);
312  }
313 
314  /* Get optional filename extension */
315  self->filename_suffix = afw_object_old_get_property_as_utf8(
316  properties, &afw_s_filenameSuffix, p, xctx);
317  if (!self->filename_suffix) {
318  self->filename_suffix = &afw_s_a_empty_string;
319  }
320 
321  /* Get root from parameters and make it full path. */
323  properties, &afw_s_root, adaptor->source_location,
324  afw_compile_type_hybrid, p, xctx);
325  if (!afw_value_is_string(value)) {
327  &afw_s_root, xctx);
328  }
329  self->root = afw_file_insure_full_path(
330  &((afw_value_string_t *)value)->internal,
331  p, xctx);
332 
333  /* Make path for journal directory. */
334  self->journal_dir_path_z = afw_utf8_z_printf(p, xctx,
336  AFW_UTF8_FMT_ARG(self->root));
337 
338  /* Make path to journal lock file. */
339  self->journal_lock_file_path_z = afw_utf8_z_printf(p, xctx,
341  AFW_UTF8_FMT_ARG(self->root));
342 
343  /* If isDevelopmentInput is true, provide appropriate object types. */
345  &afw_s_isDevelopmentInput, xctx);
346  if (b) {
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);
359  }
360 
361  /* Return adaptor. */
362  return adaptor;
363 }
364 
365 
366 /*
367  * Implementation of method destroy of interface afw_adaptor.
368  */
369 void
371  const afw_adaptor_t * instance,
372  afw_xctx_t *xctx)
373 {
374  /* Release pool. */
375  afw_pool_release(instance->p, xctx);
376 }
377 
378 
379 /*
380  * Implementation of method create_adaptor_session of interface afw_adaptor.
381  */
382 const afw_adaptor_session_t *
384  const afw_adaptor_t * instance,
385  afw_xctx_t *xctx)
386 {
389 
391  session->pub.inf = &impl_afw_adaptor_session_inf;
392  session->pub.adaptor = (afw_adaptor_t *)self;
393  session->pub.p = xctx->p;
394  session->adaptor = self;
395 
396  /* Adaptor session instance holds event journal instance. */
397  session->journal.inf = afw_file_internal_get_journal_inf();
398  session->journal.session = (afw_adaptor_session_t *)session;
399 
400  /* Return session. */
401  return (const afw_adaptor_session_t *)session;
402 }
403 
404 
405 
406 /*
407  * Implementation of method get_additional_metrics of interface afw_adaptor.
408  */
409 const afw_object_t *
411  const afw_adaptor_t * instance,
412  const afw_pool_t * p,
413  afw_xctx_t *xctx)
414 {
415  /* There are no adaptor specific metrics. */
416  return NULL;
417 }
418 
419 
420 /* Helper to get full path. */
421 AFW_DEFINE_STATIC_INLINE(const afw_utf8_t *)
422 impl_get_full_path(
424  const afw_utf8_t * object_type_id,
425  const afw_utf8_t * object_id,
426  const afw_pool_t *p, afw_xctx_t *xctx)
427 {
428  return afw_utf8_printf(p, xctx,
430  AFW_UTF8_FMT_ARG(adaptor->root),
431  AFW_UTF8_FMT_ARG(object_type_id),
432  AFW_UTF8_FMT_ARG(object_id),
433  AFW_UTF8_FMT_ARG(adaptor->filename_suffix));
434 }
435 
436 
437 /*
438  * Implementation of method destroy of interface afw_adaptor_session.
439  */
440 void
442  const afw_adaptor_session_t * instance,
443  afw_xctx_t *xctx)
444 {
445  /* Nothing to do. */
446 }
447 
448 
449 /*
450  * Implementation of method retrieve_objects for interface
451  * afw_adaptor_session.
452  */
453 void
455  const afw_adaptor_session_t *instance,
456  const afw_adaptor_impl_request_t *impl_request,
457  const afw_utf8_t *object_type_id,
458  const afw_query_criteria_t *criteria,
459  void *context,
460  afw_object_cb_t callback,
461  const afw_object_t *adaptor_type_specific,
462  const afw_pool_t *p,
463  afw_xctx_t *xctx)
464 {
466  afw_file_internal_adaptor_t *adaptor = (afw_file_internal_adaptor_t *)self->adaptor;
467  const char *dirname_z;
468  const afw_utf8_t *full_path;
469  apr_dir_t *dir;
470  apr_status_t rv;
471  apr_finfo_t finfo;
472  char err[100];
473  const afw_pool_t *obj_p;
474  const afw_object_t *obj;
475  const afw_memory_t *raw;
476  const afw_utf8_t *object_id;
477  afw_size_t len;
478 
479  /* Open ObjectType's directory. */
480  dirname_z = apr_psprintf(afw_pool_get_apr_pool(p),
481  "%" AFW_UTF8_FMT "%" AFW_UTF8_FMT "/",
482  AFW_UTF8_FMT_ARG(adaptor->root),
483  AFW_UTF8_FMT_ARG(object_type_id));
484  rv = apr_dir_open(&dir, dirname_z, afw_pool_get_apr_pool(p));
485 
486  /* If not found, return no objects. */
487  if (APR_STATUS_IS_ENOENT(rv)) {
488  callback(NULL, context, xctx);
489  return;
490  }
491 
492  /* If there is another problem, throw error. */
493  if (rv != APR_SUCCESS) {
494  AFW_THROW_ERROR_RV_Z(general, apr, rv, "apr_dir_open() failed.",
495  xctx);
496  }
497 
498  /* Process each JSON object in directory. */
499  while (1) {
500 
501  /* Read next directory entry until there are no more.*/
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);
507  AFW_THROW_ERROR_RV_Z(general, apr, rv, "apr_dir_open() failed.",
508  xctx);
509  }
510 
511  /* Skip ., .., and hidden files. */
512  if (*(finfo.name) == '.') {
513  continue;
514  }
515 
516  /* Create object from corresponding file. */
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)
523  {
524  continue;
525  }
526  len -= adaptor->filename_suffix->len;
527  }
528 
529 
530  /* Create pool for object and related memory. */
531  obj_p = afw_pool_create(p, xctx);
532 
533  /* Determine object_id and full_path. */
534  object_id = afw_utf8_create(finfo.name, len, obj_p, xctx);
535  full_path = afw_utf8_printf(obj_p, xctx,
537  AFW_UTF8_FMT_ARG(adaptor->root),
538  AFW_UTF8_FMT_ARG(object_type_id),
539  AFW_UTF8_FMT_ARG(object_id),
540  AFW_UTF8_FMT_ARG(adaptor->filename_suffix));
541 
542  /*
543  * Load file to memory and convert to object instance. Ceed control
544  * of obj_p to object.
545  */
546  raw = afw_file_to_memory(full_path, (apr_size_t)finfo.size,
547  obj_p, xctx);
549  adaptor->content_type, raw, full_path, &adaptor->pub.adaptor_id,
550  object_type_id, object_id, true, obj_p, xctx);
551 
552  /*
553  * If query criteria met, callback with object. Callback will release
554  * object. If callback returns true, prematurely stop retrieving.
555  */
556  if (afw_query_criteria_test_object(obj, criteria, p, xctx)) {
557  if (callback(obj, context, xctx)) {
558  break;
559  }
560  }
561 
562  /* If query criteria not met, release object. */
563  else {
564  afw_object_release(obj, xctx);
565  }
566  }
567 
568  /* Close ObjectType's directory. */
569  rv = apr_dir_close(dir);
570  if (rv != APR_SUCCESS) {
571  AFW_THROW_ERROR_RV_Z(general, apr, rv, "apr_dir_close() failed.",
572  xctx);
573  }
574 
575  /* Call callback one more time with NULL object pointer. */
576  callback(NULL, context, xctx);
577 }
578 
579 
580 /*
581  * Implementation of method get_object for interface afw_adaptor_session.
582  */
583 void
585  const afw_adaptor_session_t *instance,
586  const afw_adaptor_impl_request_t *impl_request,
587  const afw_utf8_t *object_type_id,
588  const afw_utf8_t *object_id,
589  void *context,
590  afw_object_cb_t callback,
591  const afw_object_t *adaptor_type_specific,
592  const afw_pool_t *p,
593  afw_xctx_t *xctx)
594 {
596  afw_file_internal_adaptor_t *adaptor = (afw_file_internal_adaptor_t *)self->adaptor;
597  const afw_utf8_t *full_path;
598  const afw_memory_t *raw;
599  const afw_object_t *object;
600  const afw_pool_t *obj_p;
601 
602  /* Create pool for object and related memory. */
603  obj_p = afw_pool_create(p, xctx);
604 
605  /* Determine full path. */
606  full_path = impl_get_full_path(adaptor, object_type_id, object_id,
607  obj_p, xctx);
608 
609  /*
610  * Load file to memory and convert to object instance. Ceed control
611  * of obj_p to object.
612  */
613  raw = afw_file_to_memory(full_path, 0, obj_p, xctx);
615  adaptor->content_type, raw, full_path,
616  &adaptor->pub.adaptor_id, object_type_id, object_id,
617  true, obj_p, xctx);
618 
619  /* Pass object to callback. Callback will release object. */
620  callback(object, context, xctx);
621 }
622 
623 
624 /*
625  * Implementation of method add_object for interface afw_adaptor_session.
626  */
627 const afw_utf8_t *
629  const afw_adaptor_session_t *instance,
630  const afw_adaptor_impl_request_t *impl_request,
631  const afw_utf8_t *object_type_id,
632  const afw_utf8_t *suggested_object_id,
633  const afw_object_t *object,
634  const afw_object_t *adaptor_type_specific,
635  afw_xctx_t *xctx)
636 {
638  afw_file_internal_adaptor_t *adaptor = (afw_file_internal_adaptor_t *)self->adaptor;
639  const afw_utf8_t *full_path;
640  const afw_memory_t *raw;
641  const afw_utf8_t *object_id;
642 
643  object_id = (suggested_object_id)
644  ? suggested_object_id
645  : afw_uuid_create_utf8(xctx->p, xctx);
646 
647  full_path = impl_get_full_path(adaptor, object_type_id, object_id,
648  xctx->p, xctx);
649  raw = afw_content_type_object_to_raw(adaptor->content_type,
651  xctx->p, xctx);
652  afw_file_from_memory(full_path, raw, afw_file_mode_write_new, xctx);
653 
654  return object_id;
655 }
656 
657 
658 /*
659  * Implementation of method modify_object for interface afw_adaptor_session.
660  */
661 void
663  const afw_adaptor_session_t *instance,
664  const afw_adaptor_impl_request_t *impl_request,
665  const afw_utf8_t *object_type_id,
666  const afw_utf8_t *object_id,
667  const afw_adaptor_modify_entry_t *const *entry,
668  const afw_object_t *adaptor_type_specific,
669  afw_xctx_t *xctx)
670 {
673  afw_file_internal_adaptor_t *adaptor =
674  (afw_file_internal_adaptor_t *)self->adaptor;
675  const afw_object_t *object;
676  const afw_utf8_t *full_path;
677  const afw_memory_t *raw;
678 
679  if (!object_id || !object_type_id) {
680  AFW_THROW_ERROR_Z(general,
681  "Missing object id or object_type.", xctx);
682  }
683 
684  /* _AdaptiveJournalEntry_ objects are read-only. */
685  if (afw_utf8_equal(object_type_id,
687  {
688  AFW_THROW_ERROR_Z(read_only,
690  " objects are read-only", xctx);
691  }
692 
693  full_path = impl_get_full_path(adaptor, object_type_id, object_id,
694  xctx->p, xctx);
695 
696  /* Get object to modify. */
697  raw = afw_file_to_memory(full_path, 0, xctx->p, xctx);
699  adaptor->content_type, raw, full_path,
700  &adaptor->pub.adaptor_id,
701  object_type_id, object_id, false, xctx->p, xctx);
702 
703  /* Apply modifications. */
705  entry, object, xctx);
706 
707  /* Write modified object. */
708  raw = afw_content_type_object_to_raw(adaptor->content_type,
710  xctx->p, xctx);
711  afw_file_from_memory(full_path, raw, afw_file_mode_write_existing,
712  xctx);
713 }
714 
715 
716 /*
717  * Implementation of method replace_object for interface afw_adaptor_session.
718  */
719 void
721  const afw_adaptor_session_t *instance,
722  const afw_adaptor_impl_request_t *impl_request,
723  const afw_utf8_t *object_type_id,
724  const afw_utf8_t *object_id,
725  const afw_object_t *replacement_object,
726  const afw_object_t *adaptor_type_specific,
727  afw_xctx_t *xctx)
728 {
730  afw_file_internal_adaptor_t *adaptor = (afw_file_internal_adaptor_t *)self->adaptor;
731  const afw_utf8_t *full_path;
732  const afw_memory_t *raw;
733 
734  if (!object_id || !object_type_id) {
735  AFW_THROW_ERROR_Z(general,
736  "Updated object missing id or object_type.", xctx);
737  }
738 
739  full_path = impl_get_full_path(adaptor, object_type_id,
740  object_id, xctx->p, xctx);
741 
742  /* Write updated object. */
743  raw = afw_content_type_object_to_raw(adaptor->content_type,
745  xctx->p, xctx);
746  afw_file_from_memory(full_path, raw, afw_file_mode_write_existing,
747  xctx);
748 }
749 
750 
751 /*
752  * Implementation of method delete_object for interface afw_adaptor_session.
753  */
754 void
756  const afw_adaptor_session_t *instance,
757  const afw_adaptor_impl_request_t *impl_request,
758  const afw_utf8_t *object_type_id,
759  const afw_utf8_t *object_id,
760  const afw_object_t *adaptor_type_specific,
761  afw_xctx_t *xctx)
762 {
764  afw_file_internal_adaptor_t *adaptor = (afw_file_internal_adaptor_t *)self->adaptor;
765  const afw_utf8_t *full_path;
766 
767  full_path = impl_get_full_path(adaptor, object_type_id, object_id,
768  xctx->p, xctx);
769  afw_file_delete(full_path, xctx);
770 }
771 
772 
773 /*
774  * Implementation of method begin_transaction of interface afw_adaptor_session.
775  */
778  const afw_adaptor_session_t * instance,
779  afw_xctx_t *xctx)
780 {
781  /* This adaptor does not support transactions. */
782  return NULL;
783 }
784 
785 
786 /*
787  * Implementation of method get_journal of interface afw_adaptor_session.
788  */
789 const afw_adaptor_journal_t *
790 impl_afw_adaptor_session_get_journal_interface(
791  const afw_adaptor_session_t * instance,
792  afw_xctx_t *xctx)
793 {
795 
796  /* Return event journal instance. */
797  return (afw_adaptor_journal_t *)&self->journal;
798 }
799 
800 
801 
802 /*
803  * Implementation of method get_key_value_interface of interface
804  * afw_adaptor_session.
805  */
808  const afw_adaptor_session_t * instance,
809  afw_xctx_t *xctx)
810 {
811  /* Key value interface is not supported by this adaptor. */
812  return NULL;
813 }
814 
815 /*
816  * Implementation of method get_index_interface of interface afw_adaptor_session.
817  */
820  const afw_adaptor_session_t * instance,
821  afw_xctx_t *xctx)
822 {
823  /* Key value interface is not supported by this adaptor. */
824  return NULL;
825 }
826 
827 
828 /*
829  * Implementation of method get_object_type_cache_interface for interface
830  * afw_adaptor_session.
831  */
833 impl_afw_adaptor_session_get_object_type_cache_interface(
834  const afw_adaptor_session_t * instance,
835  afw_xctx_t *xctx)
836 {
837  /* There is on adaptor cache. */
838  return NULL;
839 }
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.
#define AFW_IMPLEMENTATION_ID
const afw_object_t * impl_afw_adaptor_get_additional_metrics(const afw_adaptor_t *instance, const afw_pool_t *p, afw_xctx_t *xctx)
Definition: afw_file.c:410
void impl_afw_adaptor_destroy(const afw_adaptor_t *instance, afw_xctx_t *xctx)
Definition: afw_file.c:370
const afw_adaptor_session_t * impl_afw_adaptor_create_adaptor_session(const afw_adaptor_t *instance, afw_xctx_t *xctx)
Definition: afw_file.c:383
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)
Definition: afw_file.c:662
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)
Definition: afw_file.c:720
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)
Definition: afw_file.c:755
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)
Definition: afw_file.c:454
const afw_adaptor_transaction_t * impl_afw_adaptor_session_begin_transaction(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
Definition: afw_file.c:777
void impl_afw_adaptor_session_destroy(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
Definition: afw_file.c:441
const afw_adaptor_impl_index_t * impl_afw_adaptor_session_get_index_interface(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
Definition: afw_file.c:819
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)
Definition: afw_file.c:628
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)
Definition: afw_file.c:584
const afw_adaptor_key_value_t * impl_afw_adaptor_session_get_key_value_interface(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
Definition: afw_file.c:807
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.
Definition: afw_common.h:605
#define AFW_UTF8_Z_LEN
String is NUL (0) terminate.
Definition: afw_common.h:266
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.
Definition: afw_common.h:1176
#define AFW_UTF8_LITERAL(A_STRING)
String literal initializer.
Definition: afw_common.h:582
_Bool afw_boolean_t
Definition: afw_common.h:373
unsigned char afw_byte_t
A byte of memory (unsigned).
Definition: afw_common.h:208
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
Definition: afw_common.h:588
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
Definition: afw_common.h:523
char afw_utf8_octet_t
8 bits of utf-8 codepoint.
Definition: afw_common.h:236
apr_size_t afw_size_t
size_t.
Definition: afw_common.h:151
#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.
Definition: afw_error.h:702
#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.
Definition: afw_error.h:301
#define AFW_ENDTRY
Ends an AFW try block.
Definition: afw_error.h:727
#define AFW_TRY
Begin an AFW TRY block.
Definition: afw_error.h:634
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:319
#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.
Definition: afw_error.h:338
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
Definition: afw_error.h:283
afw_file_insure_full_path(const afw_utf8_t *path, const afw_pool_t *p, afw_xctx_t *xctx)
Return full file path.
Definition: afw_file.c:40
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.
Definition: afw_file.c:136
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.
Definition: afw_file.c:71
afw_file_adaptor_create_cede_p(const afw_object_t *properties, const afw_pool_t *p, afw_xctx_t *xctx)
Create a file adaptor.
Definition: afw_file.c:285
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.
Definition: afw_file.c:261
#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.
Definition: afw_object.c:531
#define AFW_OBJECT_Q_OBJECT_TYPE_ID_JOURNAL_ENTRY
Quoted object type id for Journal Entry object.
Definition: afw_object.h:60
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.
Definition: afw_object.c:436
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.
Definition: afw_object.c:252
#define AFW_OBJECT_S_OBJECT_TYPE_ID_JOURNAL_ENTRY
String object type id for Journal Entry object.
Definition: afw_object.h:63
#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.
Definition: afw_pool.h:167
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.
Definition: afw_utf8.h:369
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,...)
Definition: afw_utf8.h:854
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.
Definition: afw_utf8.h:529
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.
Definition: afw_utf8.c:459
#define afw_utf8_create(s, len, p, xctx)
Create utf-8 string without copy unless necessary in pool specified.
Definition: afw_utf8.h:239
afw_uuid_create_utf8(const afw_pool_t *p, afw_xctx_t *xctx)
Create a UUID as a standard format UUID utf-8 string.
Definition: afw_uuid.c:62
#define afw_xctx_calloc(size, xctx)
Macro to allocate cleared memory in xctx's pool.
Definition: afw_xctx.h:185
#define afw_xctx_calloc_type(type, xctx)
Macro to allocate cleared memory to hold type in xctx's pool.
Definition: afw_xctx.h:199
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.
Adaptor modify entry.
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.
Definition: afw_common.h:505
Interface afw_object public struct.
Interface afw_pool public struct.
Parsed query criteria.
NFC normalized UTF-8 string.
Definition: afw_common.h:545
Interface afw_value public struct.
struct for data type string values.
Interface afw_xctx public struct.