GnuCash  2.6.18
Files | Data Structures

Files

file  qofbackend-p.h
 private api for data storage backend
 
file  qofobject-p.h
 the Core Object Registration/Lookup Private Interface
 

Data Structures

struct  QofBackendProvider
 
struct  QofBackend
 Pseudo-object providing an interface between the engine and a persistant data store (e.g. a server, a database, or a file). More...
 

Backend_Private

Pseudo-object defining how the engine can interact with different back-ends (which may be SQL databases, or network interfaces to remote QOF servers. File-io is just one type of backend).

The callbacks will be called at the appropriate times during a book session to allow the backend to store the data as needed.

enum  QofBackendLoadType { LOAD_TYPE_INITIAL_LOAD, LOAD_TYPE_LOAD_ALL }
 
void qof_backend_register_provider (QofBackendProvider *)
 
void qof_backend_set_message (QofBackend *be, const char *format,...)
 
char * qof_backend_get_message (QofBackend *be)
 
void qof_backend_init (QofBackend *be)
 
void qof_backend_destroy (QofBackend *be)
 
gchar qof_book_get_open_marker (const QofBook *book)
 
gint32 qof_book_get_version (const QofBook *book)
 
void qof_book_set_version (QofBook *book, gint32 version)
 

Book_Private

void qof_book_set_backend (QofBook *book, QofBackend *be)
 
gboolean qof_book_register (void)
 
gchar * qof_book_normalize_counter_format_internal (const gchar *p, const gchar *gint64_format, gchar **err_msg)
 
void qof_book_print_dirty (const QofBook *book)
 
#define qof_book_set_guid(book, guid)   qof_instance_set_guid(QOF_INSTANCE(book), guid)
 

Class_Private

void qof_class_init (void)
 
void qof_class_shutdown (void)
 
QofSortFunc qof_class_get_default_sort (QofIdTypeConst obj_name)
 

Entity_Private

void qof_collection_insert_entity (QofCollection *, QofInstance *)
 
void qof_collection_mark_clean (QofCollection *)
 
void qof_collection_mark_dirty (QofCollection *)
 
void qof_collection_print_dirty (const QofCollection *col, gpointer dummy)
 

Objects_Private

void qof_object_book_begin (QofBook *book)
 
void qof_object_book_end (QofBook *book)
 
gboolean qof_object_is_dirty (const QofBook *book)
 
void qof_object_mark_clean (QofBook *book)
 
gboolean qof_object_compliance (QofIdTypeConst type_name, gboolean warn)
 check an object can be created and supports iteration More...
 

Detailed Description

Private interfaces, not meant to be used by applications.

Macro Definition Documentation

◆ qof_book_set_guid

#define qof_book_set_guid (   book,
  guid 
)    qof_instance_set_guid(QOF_INSTANCE(book), guid)
Deprecated:
use qof_instance_set_guid instead but only in backends (when reading the GncGUID from the data source).

Definition at line 61 of file qofbook-p.h.

Function Documentation

◆ qof_backend_get_message()

char* qof_backend_get_message ( QofBackend *  be)

The qof_backend_get_message() pops the error message string from the Backend. This string should be freed with g_free().

Definition at line 99 of file qofbackend.c.

100 {
101  char * msg;
102 
103  if (!be) return g_strdup("ERR_BACKEND_NO_BACKEND");
104  if (!be->error_msg) return NULL;
105 
106  /*
107  * Just return the contents of the error_msg and then set it to
108  * NULL. This is necessary, because the Backends don't seem to
109  * have a destroy_backend function to take care of freeing stuff
110  * up. The calling function should free the copy.
111  * Also, this is consistent with the qof_backend_get_error() popping.
112  */
113 
114  msg = be->error_msg;
115  be->error_msg = NULL;
116  return msg;
117 }

◆ qof_backend_register_provider()

void qof_backend_register_provider ( QofBackendProvider *  )

Let the sytem know about a new provider of backends. This function is typically called by the provider library at library load time. This function allows the backend library to tell the QOF infrastructure that it can handle URL's of a certain type. Note that a single backend library may register more than one provider, if it is capable of handling more than one URL access method.

Definition at line 102 of file qofsession.c.

103 {
104  provider_list = g_slist_append (provider_list, prov);
105 }

◆ qof_backend_set_message()

void qof_backend_set_message ( QofBackend *  be,
const char *  format,
  ... 
)

The qof_backend_set_message() assigns a string to the backend error message.

Definition at line 75 of file qofbackend.c.

76 {
77  va_list args;
78  char * buffer;
79 
80  if (!be) return;
81 
82  /* If there's already something here, free it */
83  if (be->error_msg) g_free(be->error_msg);
84 
85  if (!format)
86  {
87  be->error_msg = NULL;
88  return;
89  }
90 
91  va_start(args, format);
92  buffer = (char *)g_strdup_vprintf(format, args);
93  va_end(args);
94 
95  be->error_msg = buffer;
96 }

◆ qof_book_get_open_marker()

gchar qof_book_get_open_marker ( const QofBook *  book)

Allow backends to see if the book is open

Returns
'y' if book is open, otherwise 'n'.

◆ qof_book_get_version()

gint32 qof_book_get_version ( const QofBook *  book)

get the book version

used for tracking multiuser updates in backends.

Returns
-1 if no book exists, 0 if the book is new, otherwise the book version number.

◆ qof_book_normalize_counter_format_internal()

gchar* qof_book_normalize_counter_format_internal ( const gchar *  p,
const gchar *  gint64_format,
gchar **  err_msg 
)

Validate a counter format string with a given format specifier. If valid, returns a normalized format string, that is whatever long int specifier was used will be replaced with the value of the posix "PRIx64" macro. If not valid returns NULL and optionally set an error message is a non-null err_msg parameter was passed. The caller should free the returned format string and error message with g_free.

Definition at line 554 of file qofbook.c.

556 {
557  const gchar *conv_start, *base, *tmp = NULL;
558  gchar *normalized_str = NULL, *aux_str = NULL;
559 
560  /* Validate a counter format. This is a very simple "parser" that
561  * simply checks for a single gint64 conversion specification,
562  * allowing all modifiers and flags that printf(3) specifies (except
563  * for the * width and precision, which need an extra argument). */
564  base = p;
565 
566  /* Skip a prefix of any character except % */
567  while (*p)
568  {
569  /* Skip two adjacent percent marks, which are literal percent
570  * marks */
571  if (p[0] == '%' && p[1] == '%')
572  {
573  p += 2;
574  continue;
575  }
576  /* Break on a single percent mark, which is the start of the
577  * conversion specification */
578  if (*p == '%')
579  break;
580  /* Skip all other characters */
581  p++;
582  }
583 
584  if (!*p)
585  {
586  if (err_msg)
587  *err_msg = g_strdup("Format string ended without any conversion specification");
588  return NULL;
589  }
590 
591  /* Store the start of the conversion for error messages */
592  conv_start = p;
593 
594  /* Skip the % */
595  p++;
596 
597  /* See whether we have already reached the correct format
598  * specification (e.g. "li" on Unix, "I64i" on Windows). */
599  tmp = strstr(p, gint64_format);
600 
601  if (!tmp)
602  {
603  if (err_msg)
604  *err_msg = g_strdup_printf("Format string doesn't contain requested format specifier: %s", gint64_format);
605  return NULL;
606  }
607 
608  /* Skip any number of flag characters */
609  while (*p && (tmp != p) && strchr("#0- +'I", *p))
610  {
611  p++;
612  tmp = strstr(p, gint64_format);
613  }
614 
615  /* Skip any number of field width digits,
616  * and precision specifier digits (including the leading dot) */
617  while (*p && (tmp != p) && strchr("0123456789.", *p))
618  {
619  p++;
620  tmp = strstr(p, gint64_format);
621  }
622 
623  if (!*p)
624  {
625  if (err_msg)
626  *err_msg = g_strdup_printf("Format string ended during the conversion specification. Conversion seen so far: %s", conv_start);
627  return NULL;
628  }
629 
630  /* See if the format string starts with the correct format
631  * specification. */
632  tmp = strstr(p, gint64_format);
633  if (tmp == NULL)
634  {
635  if (err_msg)
636  *err_msg = g_strdup_printf("Invalid length modifier and/or conversion specifier ('%.4s'), it should be: %s", p, gint64_format);
637  return NULL;
638  }
639  else if (tmp != p)
640  {
641  if (err_msg)
642  *err_msg = g_strdup_printf("Garbage before length modifier and/or conversion specifier: '%*s'", (int)(tmp - p), p);
643  return NULL;
644  }
645 
646  /* Copy the string we have so far and add normalized format specifier for long int */
647  aux_str = g_strndup (base, p - base);
648  normalized_str = g_strconcat (aux_str, PRIi64, NULL);
649  g_free (aux_str);
650 
651  /* Skip length modifier / conversion specifier */
652  p += strlen(gint64_format);
653  tmp = p;
654 
655  /* Skip a suffix of any character except % */
656  while (*p)
657  {
658  /* Skip two adjacent percent marks, which are literal percent
659  * marks */
660  if (p[0] == '%' && p[1] == '%')
661  {
662  p += 2;
663  continue;
664  }
665  /* Break on a single percent mark, which is the start of the
666  * conversion specification */
667  if (*p == '%')
668  {
669  if (err_msg)
670  *err_msg = g_strdup_printf("Format string contains unescaped %% signs (or multiple conversion specifications) at '%s'", p);
671  g_free (normalized_str);
672  return NULL;
673  }
674  /* Skip all other characters */
675  p++;
676  }
677 
678  /* Add the suffix to our normalized string */
679  aux_str = normalized_str;
680  normalized_str = g_strconcat (aux_str, tmp, NULL);
681  g_free (aux_str);
682 
683  /* If we end up here, the string was valid, so return no error
684  * message */
685  return normalized_str;
686 }

◆ qof_book_print_dirty()

void qof_book_print_dirty ( const QofBook *  book)

This debugging function can be used to traverse the book structure and all subsidiary structures, printing out which structures have been marked dirty.

Definition at line 195 of file qofbook.c.

196 {
197  if (qof_book_session_not_saved(book))
198  PINFO("book is dirty.");
199  qof_book_foreach_collection
200  (book, (QofCollectionForeachCB)qof_collection_print_dirty, NULL);
201 }
void(* QofCollectionForeachCB)(QofCollection *, gpointer user_data)
Definition: qofbook.h:206
#define PINFO(format, args...)
Definition: qoflog.h:244
gboolean qof_book_session_not_saved(const QofBook *book)
Definition: qofbook.c:159

◆ qof_collection_insert_entity()

void qof_collection_insert_entity ( QofCollection *  ,
QofInstance *   
)

Take entity, remove it from whatever collection its currently in, and place it in a new collection. To be used only for moving entity from one book to another.

Definition at line 94 of file qofid.c.

95 {
96  const GncGUID *guid;
97 
98  if (!col || !ent) return;
99  guid = qof_instance_get_guid(ent);
100  if (guid_equal(guid, guid_null())) return;
101  g_return_if_fail (col->e_type == ent->e_type);
102  qof_collection_remove_entity (ent);
103  g_hash_table_insert (col->hash_of_entities, (gpointer)guid, ent);
104  qof_instance_set_collection(ent, col);
105 }
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Definition: qofinstance.c:473
Definition: guid.h:54
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Definition: guid.c:708
const GncGUID * guid_null(void)
Definition: guid.c:125

◆ qof_collection_mark_clean()

void qof_collection_mark_clean ( QofCollection *  )

reset value of dirty flag

Definition at line 257 of file qofid.c.

258 {
259  if (col)
260  {
261  col->is_dirty = FALSE;
262  }
263 }

◆ qof_object_book_begin()

void qof_object_book_begin ( QofBook *  book)

To be called from within the book

Definition at line 93 of file qofobject.c.

94 {
95  GList *l;
96 
97  if (!book) return;
98  ENTER (" ");
99  for (l = object_modules; l; l = l->next)
100  {
101  QofObject *obj = l->data;
102  if (obj->book_begin)
103  obj->book_begin (book);
104  }
105 
106  /* Remember this book for later */
107  book_list = g_list_prepend (book_list, book);
108  LEAVE (" ");
109 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ qof_object_compliance()

gboolean qof_object_compliance ( QofIdTypeConst  type_name,
gboolean  warn 
)

check an object can be created and supports iteration

Parameters
type_nameobject to check
warnIf called only once per operation, pass TRUE to log objects that fail the compliance check. To prevent repeated log messages when calling more than once, pass FALSE.
Returns
TRUE if object can be created and supports iteration, else FALSE.

Definition at line 180 of file qofobject.c.

181 {
182  const QofObject *obj;
183 
184  obj = qof_object_lookup(type_name);
185  if ((obj->create == NULL) || (obj->foreach == NULL))
186  {
187  if (warn)
188  {
189  PINFO (" Object type %s is not fully QOF compliant", obj->e_type);
190  }
191  return FALSE;
192  }
193  return TRUE;
194 }
#define PINFO(format, args...)
Definition: qoflog.h:244
const QofObject * qof_object_lookup(QofIdTypeConst name)
Definition: qofobject.c:346