35 gchar *scheme = NULL, *hostname = NULL;
36 gchar *username = NULL, *password = NULL;
39 gboolean is_uri = FALSE;
42 &username, &password, &path );
63 gboolean is_known_scheme = FALSE;
67 for ( node = known_scheme_list; node != NULL; node = node->next )
69 gchar *known_scheme = node->data;
70 if ( !g_ascii_strcasecmp (scheme, known_scheme) )
72 is_known_scheme = TRUE;
77 g_list_free (known_scheme_list);
78 return is_known_scheme;
93 (!g_ascii_strcasecmp (scheme,
"file") ||
94 !g_ascii_strcasecmp (scheme,
"xml") ||
95 !g_ascii_strcasecmp (scheme,
"sqlite3")));
116 gchar *scheme = NULL, *hostname = NULL;
117 gchar *username = NULL, *password = NULL;
120 gboolean is_local_fs = FALSE;
123 &username, &password, &path );
152 gchar *url = NULL, *tmpusername = NULL, *tmphostname = NULL;
153 gchar *delimiter = NULL;
162 g_return_if_fail( uri != NULL && strlen (uri) > 0);
164 splituri = g_strsplit ( uri,
"://", 2 );
165 if ( splituri[1] == NULL )
169 *path = g_strdup ( uri );
170 g_strfreev ( splituri );
175 *scheme = g_strdup ( splituri[0] );
182 if (g_str_has_prefix (splituri[1],
"/") &&
183 ((g_strstr_len (splituri[1], -1,
":/") != NULL) || (g_strstr_len (splituri[1], -1,
":\\") != NULL)))
185 gchar *ptr = splituri[1];
190 g_strfreev ( splituri );
197 url = g_strdup (splituri[1]);
198 g_strfreev ( splituri );
203 delimiter = g_strrstr ( url,
"@" );
204 if ( delimiter != NULL )
209 tmphostname = delimiter + 1;
214 delimiter = g_strstr_len ( tmpusername, -1,
":" );
215 if ( delimiter != NULL )
219 *password = g_strdup ( (
const gchar*)(delimiter + 1) );
221 *username = g_strdup ( (
const gchar*)tmpusername );
230 delimiter = g_strstr_len ( tmphostname, -1,
"/" );
231 if ( delimiter != NULL )
237 *path = g_strdup ( (
const gchar*)(delimiter + 1) );
241 delimiter = g_strstr_len ( tmphostname, -1,
":" );
242 if ( delimiter != NULL )
245 *port = g_ascii_strtoll ( delimiter + 1, NULL, 0 );
248 *hostname = g_strdup ( (
const gchar*)tmphostname );
258 gchar *scheme = NULL;
259 gchar *hostname = NULL;
261 gchar *username = NULL;
262 gchar *password = NULL;
266 &username, &password, &path );
278 gchar *scheme = NULL;
279 gchar *hostname = NULL;
281 gchar *username = NULL;
282 gchar *password = NULL;
286 &username, &password, &path );
298 const gchar *hostname,
300 const gchar *username,
301 const gchar *password,
304 gchar *userpass = NULL, *portstr = NULL, *uri = NULL;
306 g_return_val_if_fail( path != 0, NULL );
319 abs_path = g_strdup ( path );
324 uri_scheme = g_strdup (
"file");
326 uri_scheme = g_strdup (scheme);
343 if (g_str_has_prefix (abs_path,
"/") || g_str_has_prefix (abs_path,
"\\"))
344 uri = g_strdup_printf (
"%s://%s", uri_scheme, abs_path );
346 uri = g_strdup_printf (
"%s:///%s", uri_scheme, abs_path );
357 g_return_val_if_fail( hostname != 0, NULL );
359 if ( username != NULL && *username )
361 if ( password != NULL && *password )
362 userpass = g_strdup_printf (
"%s:%s@", username, password );
364 userpass = g_strdup_printf (
"%s@", username );
367 userpass = g_strdup (
"" );
370 portstr = g_strdup_printf (
":%d", port );
372 portstr = g_strdup (
"" );
376 uri = g_strconcat ( scheme,
"://", userpass, hostname, portstr,
"/", path, NULL );
387 gchar *scheme = NULL;
388 gchar *hostname = NULL;
390 gchar *username = NULL;
391 gchar *password = NULL;
393 gchar *newuri = NULL;
396 &username, &password, &path );
399 username, password, path);
402 username, NULL, path);
415 g_return_val_if_fail( uri != 0, NULL );
421 return g_strdup( uri );
424 if ( g_str_has_suffix( uri, extension ) )
425 return g_strdup( uri );
428 return g_strconcat( uri, extension, NULL );
Encapsulates a connection to a backend (persistent store)
gchar * gnc_uri_get_scheme(const gchar *uri)
Extracts the scheme from a uri.
gboolean gnc_uri_is_file_uri(const gchar *uri)
Checks if the given uri defines a file (as opposed to a network service like a database or web url) ...
gboolean gnc_uri_is_file_scheme(const gchar *scheme)
Checks if the given scheme is used to refer to a file (as opposed to a network service like a databas...
gchar * gnc_uri_get_path(const gchar *uri)
Extracts the path part from a uri.
void gnc_uri_get_components(const gchar *uri, gchar **scheme, gchar **hostname, gint32 *port, gchar **username, gchar **password, gchar **path)
Converts a uri in separate components.
gboolean gnc_uri_is_uri(const gchar *uri)
Checks if the given uri is a valid uri.
gchar * gnc_resolve_file_path(const gchar *filefrag)
The gnc_resolve_file_path() routine is a utility that will accept a fragmentary filename as input...
gchar * gnc_uri_normalize_uri(const gchar *uri, gboolean allow_password)
Composes a normalized uri starting from any uri (filename, db spec,...).
GList * qof_backend_get_registered_access_method_list(void)
Return a list of strings for the registered access methods.
gchar * gnc_uri_add_extension(const gchar *uri, const gchar *extension)
Adds an extension to the uri if:
gboolean gnc_uri_targets_local_fs(const gchar *uri)
Checks if the given uri is either a valid file uri or a local filesystem path.
gboolean gnc_uri_is_known_scheme(const gchar *scheme)
Checks if there is a backend that explicitly stated to handle the given scheme.
Utility functions for convert uri in separate components and back.
File path resolution utility functions.
gchar * gnc_uri_create_uri(const gchar *scheme, const gchar *hostname, gint32 port, const gchar *username, const gchar *password, const gchar *path)
Composes a normalized uri starting from its separate components.