Begin this session.
252{
253
254
255 ENTER (
" sess=%p mode=%d, URI=%s",
this, mode, new_uri);
256 clear_error ();
257
258 if (m_uri.size ())
259 {
261 push_error (ERR_BACKEND_LOCKED, {});
262 LEAVE(
"push error book is already open ");
263 return;
264 }
265
266
267 if (!new_uri)
268 {
271 LEAVE(
"push error missing new_uri");
272 return;
273 }
274
275 char * scheme {g_uri_parse_scheme (new_uri)};
276 char * filename {nullptr};
277 if (g_strcmp0 (scheme, "file") == 0)
279 else if (!scheme)
280 filename = g_strdup (new_uri);
281
282 if (filename && g_file_test (filename, G_FILE_TEST_IS_DIR))
283 {
286 g_free (filename);
287 g_free (scheme);
288 LEAVE(
"Can't open a directory");
289 return;
290 }
291
292 destroy_backend ();
293
294 m_uri = new_uri;
296 if (filename)
297 load_backend ("file");
298 else
299 load_backend (scheme);
300 g_free (filename);
301 g_free (scheme);
302
303
304 if (m_backend == nullptr)
305 {
306 m_uri = {};
309 LEAVE (
" BAD: no backend: sess=%p book-id=%s",
310 this, new_uri);
311 return;
312 }
313
314
316 PINFO (
"Done running session_begin on backend");
319 if (err != ERR_BACKEND_NO_ERR)
320 {
321 m_uri = {};
322 push_error (err, msg);
323 LEAVE (
" backend error %d %s", err, msg.empty() ?
"(null)" : msg.c_str());
324 return;
325 }
326 if (!msg.empty())
327 {
328 PWARN(
"%s", msg.c_str());
329 }
330
331 LEAVE (
" sess=%p book-id=%s",
this, new_uri);
332}
QofBackendError
The errors that can be reported to the GUI & other front-end users.
@ ERR_BACKEND_BAD_URL
Can't parse url.
@ SESSION_NEW_STORE
Open will fail if the URI doesn't exist or is locked.
@ SESSION_NEW_OVERWRITE
Create a new store at the URI.
#define PINFO(format, args...)
Print an informational note.
#define PWARN(format, args...)
Log a warning.
virtual void session_begin(QofSession *session, const char *new_uri, SessionOpenMode mode)=0
Open the file or connect to the server.
const std::string && get_message()
Retrieve and clear the stored error message.
QofBackendError get_error()
Retrieve the currently-stored error and clear it.
gchar * gnc_uri_get_path(const gchar *uri)
Extracts the path part from a uri.
QofBackendError get_error() noexcept
Returns and clears the local cached error.