From f9502e04ef209dd2d591a0bc3d922354bb084e2a Mon Sep 17 00:00:00 2001 From: Phil Longstaff Date: Sun, 13 Jul 2008 16:01:18 +0000 Subject: [PATCH] Add new method qof_backend_get_registered_access_method_list() which returns a GList of the access_method strings from the registered backends. Modify xaccResolveURL() to get and use this list rather than using hard-wired "gda" and "postgres" access methods. "http", "https", "file" and "xml" are still hard-wired in xaccResolveURL(). git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gda-dev2@17321 57a11ea4-9604-0410-9ed3-97b8803252fd --- lib/libqof/qof/qofsession.c | 14 ++++++++++++++ lib/libqof/qof/qofsession.h | 5 +++++ src/engine/gnc-filepath-utils.c | 24 +++++++++++++++++++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/lib/libqof/qof/qofsession.c b/lib/libqof/qof/qofsession.c index f19af9240a..0992503b7b 100644 --- a/lib/libqof/qof/qofsession.c +++ b/lib/libqof/qof/qofsession.c @@ -63,6 +63,20 @@ qof_backend_register_provider (QofBackendProvider *prov) provider_list = g_slist_append (provider_list, prov); } +GList* +qof_backend_get_registered_access_method_list(void) +{ + GList* list = NULL; + GSList* node; + + for( node = provider_list; node != NULL; node = node->next ) { + QofBackendProvider *prov = node->data; + list = g_list_append( list, (gchar*)prov->access_method ); + } + + return list; +} + /* ====================================================================== */ /* hook routines */ diff --git a/lib/libqof/qof/qofsession.h b/lib/libqof/qof/qofsession.h index 8f1f72af34..32f4e1b267 100644 --- a/lib/libqof/qof/qofsession.h +++ b/lib/libqof/qof/qofsession.h @@ -436,5 +436,10 @@ gboolean qof_session_export (QofSession *tmp_session, QofSession *real_session, QofPercentageFunc percentage_func); +/** Return a list of strings for the registered access methods. The owner is + * responsible for freeing the list but not the strings. + */ +GList* qof_backend_get_registered_access_method_list(void); + #endif /* QOF_SESSION_H */ /** @} */ diff --git a/src/engine/gnc-filepath-utils.c b/src/engine/gnc-filepath-utils.c index 2b8df8b766..3ad100addc 100644 --- a/src/engine/gnc-filepath-utils.c +++ b/src/engine/gnc-filepath-utils.c @@ -285,6 +285,9 @@ xaccResolveFilePath (const char * filefrag) char * xaccResolveURL (const char * pathfrag) { + GList* list; + GList* node; + /* seriously invalid */ if (!pathfrag) return NULL; @@ -296,13 +299,28 @@ xaccResolveURL (const char * pathfrag) */ if (!g_ascii_strncasecmp (pathfrag, "http://", 7) || - !g_ascii_strncasecmp (pathfrag, "https://", 8) || - !g_ascii_strncasecmp (pathfrag, "gda://", 6) || - !g_ascii_strncasecmp (pathfrag, "postgres://", 11)) + !g_ascii_strncasecmp (pathfrag, "https://", 8)) { return g_strdup(pathfrag); } + /* Check the URL against the list of registered access methods */ + list = qof_backend_get_registered_access_method_list(); + for( node = list; node != NULL; node = node->next ) { + const gchar* access_method = node->data; + if( strcmp( access_method, "file" ) != 0 && + strcmp( access_method, "xml" ) != 0 ) { + gchar s[30]; + sprintf( s, "%s://", access_method ); + if( !g_ascii_strncasecmp( pathfrag, s, strlen(s) ) ) { + g_list_free(list); + return g_strdup(pathfrag); + } + } + } + g_list_free(list); + + /* "file:" and "xml:" are handled specially */ if (!g_ascii_strncasecmp (pathfrag, "file:", 5)) { return (xaccResolveFilePath (pathfrag)); }