GnuCash  5.6-150-g038405b370+
Public Member Functions
QofXmlBackendProvider Struct Reference
Inheritance diagram for QofXmlBackendProvider:
QofBackendProvider

Public Member Functions

 QofXmlBackendProvider (const char *name, const char *type)
 
 QofXmlBackendProvider (QofXmlBackendProvider &)=delete
 
QofXmlBackendProvider operator= (QofXmlBackendProvider &)=delete
 
 QofXmlBackendProvider (QofXmlBackendProvider &&)=delete
 
QofXmlBackendProvider operator= (QofXmlBackendProvider &&)=delete
 
QofBackendcreate_backend (void)
 Return a new, fully initialized backend. More...
 
bool type_check (const char *type)
 Distinguish two providers with same access method. More...
 
- Public Member Functions inherited from QofBackendProvider
 QofBackendProvider (const char *name, const char *type)
 
 QofBackendProvider (QofBackendProvider &)=delete
 
 QofBackendProvider (QofBackendProvider &&)=delete
 

Additional Inherited Members

- Data Fields inherited from QofBackendProvider
const char * provider_name
 Some arbitrary name given for this particular backend provider.
 
const char * access_method
 The access method that this provider provides, for example, file:// http:// postgres:// or sqlite://, but without the :// at the end.
 

Detailed Description

Definition at line 100 of file gnc-backend-xml.cpp.

Member Function Documentation

◆ create_backend()

QofBackend* QofXmlBackendProvider::create_backend ( void  )
inlinevirtual

Return a new, fully initialized backend.

If the backend supports configuration, all configuration options should be initialised to usable values here.

Implements QofBackendProvider.

Definition at line 109 of file gnc-backend-xml.cpp.

109 { return new GncXmlBackend; }

◆ type_check()

bool QofXmlBackendProvider::type_check ( const char *  )
virtual

Distinguish two providers with same access method.

More than 1 backend can be registered under the same access_method, so each one is passed the path to the data (e.g. a file) and should return TRUE only:

  1. if the backend recognises the type as one that it can load and write or
  2. if the path contains no data but can be used (e.g. a new session).

    Note
    If the backend can cope with more than one type, the backend should not try to store or cache the sub-type for this data. It is sufficient only to return TRUE if any ONE of the supported types match the incoming data. The backend should not assume that returning TRUE will mean that the data will naturally follow.

Implements QofBackendProvider.

Definition at line 115 of file gnc-backend-xml.cpp.

116 {
117  GStatBuf sbuf;
118  int rc;
119  FILE* t;
120  gchar* filename;
121  QofBookFileType xml_type;
122  gboolean result;
123 
124  if (!uri)
125  {
126  return FALSE;
127  }
128 
129  filename = gnc_uri_get_path (uri);
130  t = g_fopen (filename, "r");
131  if (!t)
132  {
133  PINFO (" new file");
134  result = TRUE;
135  goto det_exit;
136  }
137  fclose (t);
138  rc = g_stat (filename, &sbuf);
139  if (rc < 0)
140  {
141  result = FALSE;
142  goto det_exit;
143  }
144  if (sbuf.st_size == 0)
145  {
146  PINFO (" empty file");
147  result = TRUE;
148  goto det_exit;
149  }
150  xml_type = gnc_is_xml_data_file_v2 (filename, NULL);
151  if ((xml_type == GNC_BOOK_XML2_FILE) ||
152  (xml_type == GNC_BOOK_XML1_FILE) ||
153  (xml_type == GNC_BOOK_POST_XML2_0_0_FILE))
154  {
155  result = TRUE;
156  goto det_exit;
157  }
158  PINFO (" %s is not a gnc XML file", filename);
159  result = FALSE;
160 
161 det_exit:
162  g_free (filename);
163  return result;
164 }
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
gchar * gnc_uri_get_path(const gchar *uri)
Extracts the path part from a uri.

The documentation for this struct was generated from the following file: