mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
gnc-uri - refer to 'scheme' instead of 'protocol' as that's the more formal term used in uris
This involves renaming 3 functions: gnc_uri_get_protocol -> gnc_uri_get_scheme gnc_uri_is_known_protocol -> gnc_uri_is_known_scheme gnc_uri_is_file_protocol -> gnc_uri_is_file_scheme The *_protocol variants are marked as deprecated. Additionally a number of local variables have been renamed from protocol to scheme to support this change.
This commit is contained in:
parent
74ed802eae
commit
d22e1db340
@ -65,5 +65,6 @@
|
||||
#endif
|
||||
|
||||
/* ENABLE macro defaults */
|
||||
#define GNC_DEPRECATED(message) __attribute__ ((__deprecated__ (message)))
|
||||
|
||||
#endif /* GNC_PLATFORM_H */
|
||||
|
@ -81,7 +81,7 @@ geturl( FileAccessWindow* faw )
|
||||
gchar* path = NULL;
|
||||
|
||||
type = gtk_combo_box_text_get_active_text (faw->cb_uri_type);
|
||||
if (gnc_uri_is_file_protocol (type))
|
||||
if (gnc_uri_is_file_scheme (type))
|
||||
{
|
||||
path = gtk_file_chooser_get_filename (faw->fileChooser);
|
||||
if ( !path ) /* file protocol was chosen but no filename was set */
|
||||
|
@ -658,7 +658,7 @@ gnc_post_file_open (GtkWindow *parent, const char * filename, gboolean is_readon
|
||||
char * newfile;
|
||||
QofBackendError io_err = ERR_BACKEND_NO_ERR;
|
||||
|
||||
gchar *protocol = NULL;
|
||||
gchar *scheme = NULL;
|
||||
gchar *hostname = NULL;
|
||||
gchar *username = NULL;
|
||||
gchar *password = NULL;
|
||||
@ -681,7 +681,7 @@ RESTART:
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gnc_uri_get_components (newfile, &protocol, &hostname,
|
||||
gnc_uri_get_components (newfile, &scheme, &hostname,
|
||||
&port, &username, &password, &path);
|
||||
|
||||
/* If the file to open is a database, and no password was given,
|
||||
@ -690,24 +690,24 @@ RESTART:
|
||||
* cancel this dialog, in which case the open file action will be
|
||||
* abandoned.
|
||||
* Note newfile is normalized uri so we can safely call
|
||||
* gnc_uri_is_file_protocol on it.
|
||||
* gnc_uri_is_file_scheme on it.
|
||||
*/
|
||||
if (!gnc_uri_is_file_protocol (protocol) && !password)
|
||||
if (!gnc_uri_is_file_scheme (scheme) && !password)
|
||||
{
|
||||
gboolean have_valid_pw = FALSE;
|
||||
have_valid_pw = gnc_keyring_get_password ( NULL, protocol, hostname, port,
|
||||
have_valid_pw = gnc_keyring_get_password ( NULL, scheme, hostname, port,
|
||||
path, &username, &password );
|
||||
if (!have_valid_pw)
|
||||
return FALSE;
|
||||
|
||||
/* Got password. Recreate the uri to use internally. */
|
||||
g_free ( newfile );
|
||||
newfile = gnc_uri_create_uri ( protocol, hostname, port,
|
||||
newfile = gnc_uri_create_uri ( scheme, hostname, port,
|
||||
username, password, path);
|
||||
}
|
||||
|
||||
/* For file based uri's, remember the directory as the default. */
|
||||
if (gnc_uri_is_file_protocol(protocol))
|
||||
if (gnc_uri_is_file_scheme(scheme))
|
||||
{
|
||||
gchar *default_dir = g_path_get_dirname(path);
|
||||
gnc_set_default_directory (GNC_PREFS_GROUP_OPEN_SAVE, default_dir);
|
||||
@ -868,8 +868,8 @@ RESTART:
|
||||
/* If the new "file" is a database, attempt to store the password
|
||||
* in a keyring. GnuCash itself will not save it.
|
||||
*/
|
||||
if ( !gnc_uri_is_file_protocol (protocol))
|
||||
gnc_keyring_set_password ( protocol, hostname, port,
|
||||
if ( !gnc_uri_is_file_scheme (scheme))
|
||||
gnc_keyring_set_password ( scheme, hostname, port,
|
||||
path, username, password );
|
||||
|
||||
xaccLogDisable();
|
||||
@ -967,7 +967,7 @@ RESTART:
|
||||
}
|
||||
}
|
||||
|
||||
g_free (protocol);
|
||||
g_free (scheme);
|
||||
g_free (hostname);
|
||||
g_free (username);
|
||||
g_free (password);
|
||||
@ -1164,7 +1164,7 @@ gnc_file_do_export(GtkWindow *parent, const char * filename)
|
||||
gchar *newfile;
|
||||
const gchar *oldfile;
|
||||
|
||||
gchar *protocol = NULL;
|
||||
gchar *scheme = NULL;
|
||||
gchar *hostname = NULL;
|
||||
gchar *username = NULL;
|
||||
gchar *password = NULL;
|
||||
@ -1185,17 +1185,17 @@ gnc_file_do_export(GtkWindow *parent, const char * filename)
|
||||
|
||||
newfile = gnc_uri_add_extension (norm_file, GNC_DATAFILE_EXT);
|
||||
g_free (norm_file);
|
||||
gnc_uri_get_components (newfile, &protocol, &hostname,
|
||||
gnc_uri_get_components (newfile, &scheme, &hostname,
|
||||
&port, &username, &password, &path);
|
||||
|
||||
/* Save As can't use the generic 'file' protocol. If the user didn't set
|
||||
* a specific protocol, assume the default 'xml'.
|
||||
*/
|
||||
if (g_strcmp0 (protocol, "file") == 0)
|
||||
if (g_strcmp0 (scheme, "file") == 0)
|
||||
{
|
||||
g_free (protocol);
|
||||
protocol = g_strdup ("xml");
|
||||
norm_file = gnc_uri_create_uri (protocol, hostname, port,
|
||||
g_free (scheme);
|
||||
scheme = g_strdup ("xml");
|
||||
norm_file = gnc_uri_create_uri (scheme, hostname, port,
|
||||
username, password, path);
|
||||
g_free (newfile);
|
||||
newfile = norm_file;
|
||||
@ -1203,8 +1203,8 @@ gnc_file_do_export(GtkWindow *parent, const char * filename)
|
||||
|
||||
/* Some extra steps for file based uri's only
|
||||
* Note newfile is normalized uri so we can safely call
|
||||
* gnc_uri_is_file_protocol on it. */
|
||||
if (gnc_uri_is_file_protocol(protocol))
|
||||
* gnc_uri_is_file_scheme on it. */
|
||||
if (gnc_uri_is_file_scheme (scheme))
|
||||
{
|
||||
if (check_file_path (path))
|
||||
{
|
||||
@ -1395,7 +1395,7 @@ gnc_file_do_save_as (GtkWindow *parent, const char* filename)
|
||||
gchar *newfile;
|
||||
const gchar *oldfile;
|
||||
|
||||
gchar *protocol = NULL;
|
||||
gchar *scheme = NULL;
|
||||
gchar *hostname = NULL;
|
||||
gchar *username = NULL;
|
||||
gchar *password = NULL;
|
||||
@ -1419,17 +1419,17 @@ gnc_file_do_save_as (GtkWindow *parent, const char* filename)
|
||||
|
||||
newfile = gnc_uri_add_extension (norm_file, GNC_DATAFILE_EXT);
|
||||
g_free (norm_file);
|
||||
gnc_uri_get_components (newfile, &protocol, &hostname,
|
||||
gnc_uri_get_components (newfile, &scheme, &hostname,
|
||||
&port, &username, &password, &path);
|
||||
|
||||
/* Save As can't use the generic 'file' protocol. If the user didn't set
|
||||
* a specific protocol, assume the default 'xml'.
|
||||
*/
|
||||
if (g_strcmp0 (protocol, "file") == 0)
|
||||
if (g_strcmp0 (scheme, "file") == 0)
|
||||
{
|
||||
g_free (protocol);
|
||||
protocol = g_strdup ("xml");
|
||||
norm_file = gnc_uri_create_uri (protocol, hostname, port,
|
||||
g_free (scheme);
|
||||
scheme = g_strdup ("xml");
|
||||
norm_file = gnc_uri_create_uri (scheme, hostname, port,
|
||||
username, password, path);
|
||||
g_free (newfile);
|
||||
newfile = norm_file;
|
||||
@ -1437,8 +1437,8 @@ gnc_file_do_save_as (GtkWindow *parent, const char* filename)
|
||||
|
||||
/* Some extra steps for file based uri's only
|
||||
* Note newfile is normalized uri so we can safely call
|
||||
* gnc_uri_is_file_protocol on it. */
|
||||
if (gnc_uri_is_file_protocol(protocol))
|
||||
* gnc_uri_is_file_scheme on it. */
|
||||
if (gnc_uri_is_file_scheme (scheme))
|
||||
{
|
||||
if (check_file_path (path))
|
||||
{
|
||||
@ -1538,8 +1538,8 @@ gnc_file_do_save_as (GtkWindow *parent, const char* filename)
|
||||
/* If the new "file" is a database, attempt to store the password
|
||||
* in a keyring. GnuCash itself will not save it.
|
||||
*/
|
||||
if ( !gnc_uri_is_file_protocol (protocol))
|
||||
gnc_keyring_set_password ( protocol, hostname, port,
|
||||
if ( !gnc_uri_is_file_scheme (scheme))
|
||||
gnc_keyring_set_password ( scheme, hostname, port,
|
||||
path, username, password );
|
||||
|
||||
/* Prevent race condition between swapping the contents of the two
|
||||
|
@ -107,17 +107,17 @@ gnc_state_set_base (const QofSession *session)
|
||||
else
|
||||
{
|
||||
/* The book_uri is composed of database connection parameters. */
|
||||
gchar* protocol = NULL;
|
||||
gchar* scheme = NULL;
|
||||
gchar* host = NULL;
|
||||
gchar* dbname = NULL;
|
||||
gchar* username = NULL;
|
||||
gchar* password = NULL;
|
||||
gint portnum = 0;
|
||||
gnc_uri_get_components (uri, &protocol, &host, &portnum,
|
||||
gnc_uri_get_components (uri, &scheme, &host, &portnum,
|
||||
&username, &password, &dbname);
|
||||
|
||||
basename = g_strjoin ("_", protocol, host, username, dbname, NULL);
|
||||
g_free (protocol);
|
||||
basename = g_strjoin ("_", scheme, host, username, dbname, NULL);
|
||||
g_free (scheme);
|
||||
g_free (host);
|
||||
g_free (username);
|
||||
g_free (password);
|
||||
|
@ -152,11 +152,11 @@ struct UriStrings
|
||||
|
||||
UriStrings::UriStrings(const std::string& uri)
|
||||
{
|
||||
gchar *protocol, *host, *username, *password, *dbname;
|
||||
gchar *scheme, *host, *username, *password, *dbname;
|
||||
int portnum;
|
||||
gnc_uri_get_components(uri.c_str(), &protocol, &host, &portnum, &username,
|
||||
gnc_uri_get_components(uri.c_str(), &scheme, &host, &portnum, &username,
|
||||
&password, &dbname);
|
||||
m_protocol = std::string{protocol};
|
||||
m_protocol = std::string{scheme};
|
||||
m_host = std::string{host};
|
||||
m_dbname = std::string{dbname};
|
||||
if (username)
|
||||
@ -164,7 +164,7 @@ UriStrings::UriStrings(const std::string& uri)
|
||||
if (password)
|
||||
m_password = std::string{password};
|
||||
m_portnum = portnum;
|
||||
g_free(protocol);
|
||||
g_free(scheme);
|
||||
g_free(host);
|
||||
g_free(username);
|
||||
g_free(password);
|
||||
|
@ -248,7 +248,7 @@ setup_business (Fixture* fixture, gconstpointer pData)
|
||||
static void
|
||||
destroy_database (gchar* url)
|
||||
{
|
||||
gchar* protocol = NULL;
|
||||
gchar* scheme = NULL;
|
||||
gchar* host = NULL;
|
||||
gchar* dbname = NULL;
|
||||
gchar* username = NULL;
|
||||
@ -263,9 +263,9 @@ destroy_database (gchar* url)
|
||||
dbi_result tables;
|
||||
StrVec tblnames;
|
||||
|
||||
gnc_uri_get_components (url, &protocol, &host, &portnum,
|
||||
gnc_uri_get_components (url, &scheme, &host, &portnum,
|
||||
&username, &password, &dbname);
|
||||
if (g_strcmp0 (protocol, "postgres") == 0)
|
||||
if (g_strcmp0 (scheme, "postgres") == 0)
|
||||
#if HAVE_LIBDBI_R
|
||||
conn = dbi_conn_new_r (pgsql, dbi_instance);
|
||||
#else
|
||||
@ -273,7 +273,7 @@ destroy_database (gchar* url)
|
||||
#endif
|
||||
else
|
||||
#if HAVE_LIBDBI_R
|
||||
conn = dbi_conn_new_r (protocol, dbi_instance);
|
||||
conn = dbi_conn_new_r (scheme, dbi_instance);
|
||||
#else
|
||||
conn = dbi_conn_new (protocol);
|
||||
#endif
|
||||
|
@ -32,21 +32,21 @@
|
||||
gboolean gnc_uri_is_uri (const gchar *uri)
|
||||
{
|
||||
|
||||
gchar *protocol = NULL, *hostname = NULL;
|
||||
gchar *scheme = NULL, *hostname = NULL;
|
||||
gchar *username = NULL, *password = NULL;
|
||||
gchar *path = NULL;
|
||||
gint port = 0;
|
||||
gboolean is_uri = FALSE;
|
||||
|
||||
gnc_uri_get_components ( uri, &protocol, &hostname, &port,
|
||||
gnc_uri_get_components ( uri, &scheme, &hostname, &port,
|
||||
&username, &password, &path );
|
||||
|
||||
/* For gnucash to consider a uri valid the following must be true:
|
||||
* - protocol and path must not be NULL
|
||||
* - scheme and path must not be NULL
|
||||
* - for anything but local filesystem uris, hostname must be valid as well */
|
||||
is_uri = (protocol && path && (gnc_uri_is_file_protocol(protocol) || hostname));
|
||||
is_uri = (scheme && path && (gnc_uri_is_file_scheme(scheme) || hostname));
|
||||
|
||||
g_free (protocol);
|
||||
g_free (scheme);
|
||||
g_free (hostname);
|
||||
g_free (username);
|
||||
g_free (password);
|
||||
@ -55,44 +55,44 @@ gboolean gnc_uri_is_uri (const gchar *uri)
|
||||
return is_uri;
|
||||
}
|
||||
|
||||
/* Checks if the given protocol is used to refer to a file
|
||||
/* Checks if the given scheme is used to refer to a file
|
||||
* (as opposed to a network service)
|
||||
*/
|
||||
gboolean gnc_uri_is_known_protocol (const gchar *protocol)
|
||||
gboolean gnc_uri_is_known_scheme (const gchar *scheme)
|
||||
{
|
||||
gboolean is_known_proto = FALSE;
|
||||
gboolean is_known_scheme = FALSE;
|
||||
GList *node;
|
||||
GList *known_proto_list = qof_backend_get_registered_access_method_list();
|
||||
GList *known_scheme_list = qof_backend_get_registered_access_method_list();
|
||||
|
||||
for ( node = known_proto_list; node != NULL; node = node->next )
|
||||
for ( node = known_scheme_list; node != NULL; node = node->next )
|
||||
{
|
||||
gchar *known_proto = node->data;
|
||||
if ( !g_ascii_strcasecmp (protocol, known_proto) )
|
||||
gchar *known_scheme = node->data;
|
||||
if ( !g_ascii_strcasecmp (scheme, known_scheme) )
|
||||
{
|
||||
is_known_proto = TRUE;
|
||||
is_known_scheme = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_list_free (known_proto_list);
|
||||
return is_known_proto;
|
||||
g_list_free (known_scheme_list);
|
||||
return is_known_scheme;
|
||||
}
|
||||
|
||||
/* Checks if the given protocol is used to refer to a file
|
||||
/* Checks if the given scheme is used to refer to a file
|
||||
* (as opposed to a network service)
|
||||
* Note unknown protocols are always considered network protocols.
|
||||
* Note unknown schemes are always considered network schemes.
|
||||
*
|
||||
* *Compatibility note:*
|
||||
* This used to be the other way around before gnucash 3.4. Before
|
||||
* that unknown protocols were always considered local file system
|
||||
* uri protocols.
|
||||
* that unknown schemes were always considered local file system
|
||||
* uri schemes.
|
||||
*/
|
||||
gboolean gnc_uri_is_file_protocol (const gchar *protocol)
|
||||
gboolean gnc_uri_is_file_scheme (const gchar *scheme)
|
||||
{
|
||||
return (protocol &&
|
||||
(!g_ascii_strcasecmp (protocol, "file") ||
|
||||
!g_ascii_strcasecmp (protocol, "xml") ||
|
||||
!g_ascii_strcasecmp (protocol, "sqlite3")));
|
||||
return (scheme &&
|
||||
(!g_ascii_strcasecmp (scheme, "file") ||
|
||||
!g_ascii_strcasecmp (scheme, "xml") ||
|
||||
!g_ascii_strcasecmp (scheme, "sqlite3")));
|
||||
}
|
||||
|
||||
/* Checks if the given uri defines a file
|
||||
@ -100,10 +100,10 @@ gboolean gnc_uri_is_file_protocol (const gchar *protocol)
|
||||
*/
|
||||
gboolean gnc_uri_is_file_uri (const gchar *uri)
|
||||
{
|
||||
gchar *protocol = gnc_uri_get_protocol ( uri );
|
||||
gboolean result = gnc_uri_is_file_protocol ( protocol );
|
||||
gchar *scheme = gnc_uri_get_scheme ( uri );
|
||||
gboolean result = gnc_uri_is_file_scheme ( scheme );
|
||||
|
||||
g_free ( protocol );
|
||||
g_free ( scheme );
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -113,24 +113,24 @@ gboolean gnc_uri_is_file_uri (const gchar *uri)
|
||||
gboolean gnc_uri_targets_local_fs (const gchar *uri)
|
||||
{
|
||||
|
||||
gchar *protocol = NULL, *hostname = NULL;
|
||||
gchar *scheme = NULL, *hostname = NULL;
|
||||
gchar *username = NULL, *password = NULL;
|
||||
gchar *path = NULL;
|
||||
gint port = 0;
|
||||
gboolean is_local_fs = FALSE;
|
||||
|
||||
gnc_uri_get_components ( uri, &protocol, &hostname, &port,
|
||||
gnc_uri_get_components ( uri, &scheme, &hostname, &port,
|
||||
&username, &password, &path );
|
||||
|
||||
/* For gnucash to consider a uri to target the local fs:
|
||||
* path must not be NULL
|
||||
* AND
|
||||
* protocol should be NULL
|
||||
* scheme should be NULL
|
||||
* OR
|
||||
* protocol must be file type protocol (file, xml, sqlite) */
|
||||
is_local_fs = (path && (!protocol || gnc_uri_is_file_protocol(protocol)));
|
||||
* scheme must be file type scheme (file, xml, sqlite) */
|
||||
is_local_fs = (path && (!scheme || gnc_uri_is_file_scheme(scheme)));
|
||||
|
||||
g_free (protocol);
|
||||
g_free (scheme);
|
||||
g_free (hostname);
|
||||
g_free (username);
|
||||
g_free (password);
|
||||
@ -141,7 +141,7 @@ gboolean gnc_uri_targets_local_fs (const gchar *uri)
|
||||
|
||||
/* Splits a uri into its separate components */
|
||||
void gnc_uri_get_components (const gchar *uri,
|
||||
gchar **protocol,
|
||||
gchar **scheme,
|
||||
gchar **hostname,
|
||||
gint32 *port,
|
||||
gchar **username,
|
||||
@ -152,9 +152,9 @@ void gnc_uri_get_components (const gchar *uri,
|
||||
gchar *url = NULL, *tmpusername = NULL, *tmphostname = NULL;
|
||||
gchar *delimiter = NULL;
|
||||
|
||||
*protocol = NULL;
|
||||
*scheme = NULL;
|
||||
*hostname = NULL;
|
||||
*port = 0;
|
||||
*port = 0;
|
||||
*username = NULL;
|
||||
*password = NULL;
|
||||
*path = NULL;
|
||||
@ -164,30 +164,19 @@ void gnc_uri_get_components (const gchar *uri,
|
||||
splituri = g_strsplit ( uri, "://", 2 );
|
||||
if ( splituri[1] == NULL )
|
||||
{
|
||||
/* No protocol means simple file path.
|
||||
/* No scheme means simple file path.
|
||||
Set path to copy of the input. */
|
||||
*path = g_strdup ( uri );
|
||||
g_strfreev ( splituri );
|
||||
return;
|
||||
}
|
||||
|
||||
/* At least a protocol was found, set it here */
|
||||
*protocol = g_strdup ( splituri[0] );
|
||||
/* At least a scheme was found, set it here */
|
||||
*scheme = g_strdup ( splituri[0] );
|
||||
|
||||
if ( gnc_uri_is_file_protocol ( *protocol ) )
|
||||
if ( gnc_uri_is_file_scheme ( *scheme ) )
|
||||
{
|
||||
/* Protocol indicates file based uri.
|
||||
* Note that unknown protocols are treated as if they are
|
||||
* file-based protocols. This is done to prevent password
|
||||
* lookups on unknown protocols.
|
||||
* On the other hand, since we don't know the specifics of
|
||||
* unknown protocols, we don't attempt to return an absolute
|
||||
* pathname for them, just whatever was there.
|
||||
*/
|
||||
if ( gnc_uri_is_known_protocol ( *protocol ) )
|
||||
*path = gnc_resolve_file_path ( splituri[1] );
|
||||
else
|
||||
*path = g_strdup ( splituri[1] );
|
||||
*path = gnc_resolve_file_path ( splituri[1] );
|
||||
g_strfreev ( splituri );
|
||||
return;
|
||||
}
|
||||
@ -232,7 +221,7 @@ void gnc_uri_get_components (const gchar *uri,
|
||||
if ( delimiter != NULL )
|
||||
{
|
||||
delimiter[0] = '\0';
|
||||
if ( gnc_uri_is_file_protocol ( *protocol ) ) /* always return absolute file paths */
|
||||
if ( gnc_uri_is_file_scheme ( *scheme ) ) /* always return absolute file paths */
|
||||
*path = gnc_resolve_file_path ( (const gchar*)(delimiter + 1) );
|
||||
else /* path is no file path, so copy it as is */
|
||||
*path = g_strdup ( (const gchar*)(delimiter + 1) );
|
||||
@ -254,16 +243,16 @@ void gnc_uri_get_components (const gchar *uri,
|
||||
|
||||
}
|
||||
|
||||
gchar *gnc_uri_get_protocol (const gchar *uri)
|
||||
gchar *gnc_uri_get_scheme (const gchar *uri)
|
||||
{
|
||||
gchar *protocol = NULL;
|
||||
gchar *scheme = NULL;
|
||||
gchar *hostname = NULL;
|
||||
gint32 port = 0;
|
||||
gchar *username = NULL;
|
||||
gchar *password = NULL;
|
||||
gchar *path = NULL;
|
||||
|
||||
gnc_uri_get_components ( uri, &protocol, &hostname, &port,
|
||||
gnc_uri_get_components ( uri, &scheme, &hostname, &port,
|
||||
&username, &password, &path );
|
||||
|
||||
g_free (hostname);
|
||||
@ -271,22 +260,22 @@ gchar *gnc_uri_get_protocol (const gchar *uri)
|
||||
g_free (password);
|
||||
g_free (path);
|
||||
|
||||
return protocol;
|
||||
return scheme;
|
||||
}
|
||||
|
||||
gchar *gnc_uri_get_path (const gchar *uri)
|
||||
{
|
||||
gchar *protocol = NULL;
|
||||
gchar *scheme = NULL;
|
||||
gchar *hostname = NULL;
|
||||
gint32 port = 0;
|
||||
gchar *username = NULL;
|
||||
gchar *password = NULL;
|
||||
gchar *path = NULL;
|
||||
|
||||
gnc_uri_get_components ( uri, &protocol, &hostname, &port,
|
||||
gnc_uri_get_components ( uri, &scheme, &hostname, &port,
|
||||
&username, &password, &path );
|
||||
|
||||
g_free (protocol);
|
||||
g_free (scheme);
|
||||
g_free (hostname);
|
||||
g_free (username);
|
||||
g_free (password);
|
||||
@ -295,7 +284,7 @@ gchar *gnc_uri_get_path (const gchar *uri)
|
||||
}
|
||||
|
||||
/* Generates a normalized uri from the separate components */
|
||||
gchar *gnc_uri_create_uri (const gchar *protocol,
|
||||
gchar *gnc_uri_create_uri (const gchar *scheme,
|
||||
const gchar *hostname,
|
||||
gint32 port,
|
||||
const gchar *username,
|
||||
@ -306,23 +295,23 @@ gchar *gnc_uri_create_uri (const gchar *protocol,
|
||||
|
||||
g_return_val_if_fail( path != 0, NULL );
|
||||
|
||||
if ( (protocol == NULL) || gnc_uri_is_file_protocol ( protocol ) )
|
||||
if (!scheme || gnc_uri_is_file_scheme (scheme))
|
||||
{
|
||||
/* Compose a file based uri, which means ignore everything but
|
||||
* the protocol and the path
|
||||
* We return an absolute pathname if the protocol is known or
|
||||
* no protocol was given. For an unknown protocol, we return the
|
||||
* the scheme and the path
|
||||
* We return an absolute pathname if the scheme is known or
|
||||
* no scheme was given. For an unknown scheme, we return the
|
||||
* path info as is.
|
||||
*/
|
||||
gchar *abs_path;
|
||||
if ( protocol && (!gnc_uri_is_known_protocol (protocol)) )
|
||||
if (scheme && (!gnc_uri_is_known_scheme (scheme)) )
|
||||
abs_path = g_strdup ( path );
|
||||
else
|
||||
abs_path = gnc_resolve_file_path ( path );
|
||||
if ( protocol == NULL )
|
||||
if ( scheme == NULL )
|
||||
uri = g_strdup_printf ( "file://%s", abs_path );
|
||||
else
|
||||
uri = g_strdup_printf ( "%s://%s", protocol, abs_path );
|
||||
uri = g_strdup_printf ( "%s://%s", scheme, abs_path );
|
||||
g_free (abs_path);
|
||||
return uri;
|
||||
}
|
||||
@ -349,7 +338,7 @@ gchar *gnc_uri_create_uri (const gchar *protocol,
|
||||
|
||||
// XXX Do I have to add the slash always or are there situations
|
||||
// it is in the path already ?
|
||||
uri = g_strconcat ( protocol, "://", userpass, hostname, portstr, "/", path, NULL );
|
||||
uri = g_strconcat ( scheme, "://", userpass, hostname, portstr, "/", path, NULL );
|
||||
|
||||
g_free ( userpass );
|
||||
g_free ( portstr );
|
||||
@ -360,7 +349,7 @@ gchar *gnc_uri_create_uri (const gchar *protocol,
|
||||
|
||||
gchar *gnc_uri_normalize_uri (const gchar *uri, gboolean allow_password)
|
||||
{
|
||||
gchar *protocol = NULL;
|
||||
gchar *scheme = NULL;
|
||||
gchar *hostname = NULL;
|
||||
gint32 port = 0;
|
||||
gchar *username = NULL;
|
||||
@ -368,16 +357,16 @@ gchar *gnc_uri_normalize_uri (const gchar *uri, gboolean allow_password)
|
||||
gchar *path = NULL;
|
||||
gchar *newuri = NULL;
|
||||
|
||||
gnc_uri_get_components ( uri, &protocol, &hostname, &port,
|
||||
gnc_uri_get_components ( uri, &scheme, &hostname, &port,
|
||||
&username, &password, &path );
|
||||
if (allow_password)
|
||||
newuri = gnc_uri_create_uri ( protocol, hostname, port,
|
||||
newuri = gnc_uri_create_uri ( scheme, hostname, port,
|
||||
username, password, path);
|
||||
else
|
||||
newuri = gnc_uri_create_uri ( protocol, hostname, port,
|
||||
newuri = gnc_uri_create_uri ( scheme, hostname, port,
|
||||
username, /* no password */ NULL, path);
|
||||
|
||||
g_free (protocol);
|
||||
g_free (scheme);
|
||||
g_free (hostname);
|
||||
g_free (username);
|
||||
g_free (password);
|
||||
@ -403,3 +392,25 @@ gchar *gnc_uri_add_extension ( const gchar *uri, const gchar *extension )
|
||||
/* Ok, all tests passed, let's add the extension */
|
||||
return g_strconcat( uri, extension, NULL );
|
||||
}
|
||||
|
||||
|
||||
/* Deprecated functions
|
||||
* ********************/
|
||||
|
||||
/* replaced with gnc_uri_get_scheme */
|
||||
gchar *gnc_uri_get_protocol (const gchar *uri)
|
||||
{
|
||||
return gnc_uri_get_scheme (uri);
|
||||
}
|
||||
|
||||
/* replaced with gnc_uri_is_known_scheme */
|
||||
gboolean gnc_uri_is_known_protocol (const gchar *protocol)
|
||||
{
|
||||
return gnc_uri_is_known_scheme(protocol);
|
||||
}
|
||||
|
||||
/* replaced with gnc_uri_is_file_scheme */
|
||||
gboolean gnc_uri_is_file_protocol (const gchar *protocol)
|
||||
{
|
||||
return gnc_uri_is_file_scheme (protocol);
|
||||
}
|
||||
|
@ -31,12 +31,12 @@
|
||||
* @author Copyright (C) 2010 Geert Janssens <janssens-geert@telenet.be>
|
||||
*
|
||||
* These functions help you convert a uri into its separate components
|
||||
* (being protocol, host name, port, user name, password and path) or
|
||||
* (being scheme, host name, port, user name, password and path) or
|
||||
* to compose a uri from these separate components.
|
||||
*
|
||||
* A full uri can be described as:
|
||||
* For GnuCash' purposes a full uri can be described as:
|
||||
*
|
||||
* @li @c proto://[[username[:password]@]hostname[:port]]/path (universal uri)
|
||||
* @li @c scheme://[[username[:password]@]hostname[:port]]/path (universal uri)
|
||||
* @li @c file://[localhost]/path (uri refering to a file on the local file system)
|
||||
*
|
||||
* Anything in square brackets is optional.
|
||||
@ -61,9 +61,11 @@
|
||||
#define GNC_DATAFILE_EXT ".gnucash"
|
||||
#define GNC_LOGFILE_EXT ".log"
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
/** Checks if the given uri is a valid uri
|
||||
*
|
||||
* A valid uri is defined by having at least a protocol and a path.
|
||||
* A valid uri is defined by having at least a scheme and a path.
|
||||
* If the uri is not referring to a file on the local file system
|
||||
* a hostname should be set as well.
|
||||
*
|
||||
@ -81,8 +83,8 @@ gboolean gnc_uri_is_uri (const gchar *uri);
|
||||
*
|
||||
* @param uri The uri to convert
|
||||
*
|
||||
* @param protocol The protocol for this uri. If the uri didn't have an
|
||||
* explicit protocol, NULL will be returned.
|
||||
* @param scheme The scheme for this uri. If the uri doesn't have an
|
||||
* explicit scheme, NULL will be returned.
|
||||
* @param hostname The host name of the server to connect to. In case of
|
||||
* the local file system path, NULL will be returned
|
||||
* @param port An optional port to connect to or 0 if the default port is to
|
||||
@ -94,25 +96,25 @@ gboolean gnc_uri_is_uri (const gchar *uri);
|
||||
*/
|
||||
|
||||
void gnc_uri_get_components (const gchar *uri,
|
||||
gchar **protocol,
|
||||
gchar **scheme,
|
||||
gchar **hostname,
|
||||
gint32 *port,
|
||||
gchar **username,
|
||||
gchar **password,
|
||||
gchar **path);
|
||||
|
||||
/** Extracts the protocol from a uri
|
||||
/** Extracts the scheme from a uri
|
||||
*
|
||||
* The function allocates memory for the protocol. The calling function should
|
||||
* The function allocates memory for the scheme. The calling function should
|
||||
* free this memory with g_free if it no longer needs the string.
|
||||
*
|
||||
* @param uri The uri to extract the protocol from
|
||||
* @param uri The uri to extract the scheme from
|
||||
*
|
||||
* @return The protocol for this uri. If the uri didn't have an
|
||||
* explicit protocol, NULL will be returned.
|
||||
* @return The scheme for this uri. If the uri didn't have an
|
||||
* explicit scheme, NULL will be returned.
|
||||
*/
|
||||
|
||||
gchar *gnc_uri_get_protocol (const gchar *uri);
|
||||
gchar *gnc_uri_get_scheme (const gchar *uri);
|
||||
|
||||
/** Extracts the path part from a uri
|
||||
*
|
||||
@ -121,7 +123,7 @@ gchar *gnc_uri_get_protocol (const gchar *uri);
|
||||
*
|
||||
* @param uri The uri to extract the path part from
|
||||
*
|
||||
* @return The protocol for this uri, or NULL if no path could be extracted.
|
||||
* @return The path for this uri, or NULL if no path could be extracted.
|
||||
*/
|
||||
|
||||
gchar *gnc_uri_get_path (const gchar *uri);
|
||||
@ -131,31 +133,31 @@ gchar *gnc_uri_get_path (const gchar *uri);
|
||||
* The resulting uri will take either of these forms:
|
||||
* @li @c file:///some/absolute/path (file could also be xml or sqlite)
|
||||
* @li @c file://c:\\some\\windows\\path (file could also be xml or sqlite)
|
||||
* @li @c protocol://[user[:password]@]hostname[:port]/path
|
||||
* @li @c scheme://[user[:password]@]hostname[:port]/path
|
||||
*
|
||||
* Only the components that are provided will be inserted in the uri. However
|
||||
* if no protocol has been provided, 'file' will be used as default protocol.
|
||||
* if no scheme has been provided, 'file' will be used as default scheme.
|
||||
*
|
||||
* The function allocates memory for the uri. The calling function should
|
||||
* free this memory with g_free the uri is no longer needed.
|
||||
*
|
||||
* @param protocol The protocol for this uri. If NULL,, 'file' will be used
|
||||
* @param scheme The scheme for this uri. If NULL,, 'file' will be used
|
||||
* in the uri.
|
||||
* @param hostname The host name of the server to connect to. This will be
|
||||
* ignored for the 'file' type protocols ('file', 'xml', 'sqlite').
|
||||
* ignored for the 'file' type schemes ('file', 'xml', 'sqlite').
|
||||
* @param port An optional port to set o, the uri, or 0 if no port is to be
|
||||
* set. This will be ignored for the 'file' type protocols ('file', 'xml',
|
||||
* set. This will be ignored for the 'file' type schemes ('file', 'xml',
|
||||
* 'sqlite').
|
||||
* @param username Optional user name to set in the uri or NULL otherwise. This will
|
||||
* be ignored for the 'file' type protocols ('file', 'xml', 'sqlite').
|
||||
* be ignored for the 'file' type schemes ('file', 'xml', 'sqlite').
|
||||
* @param password Optional password to set in the uri or NULL otherwise. This will
|
||||
* be ignored for the 'file' type protocols ('file', 'xml', 'sqlite').
|
||||
* be ignored for the 'file' type schemes ('file', 'xml', 'sqlite').
|
||||
* @param path The path to set in the uri.
|
||||
*
|
||||
* @return The normalized uri.
|
||||
*/
|
||||
|
||||
gchar *gnc_uri_create_uri (const gchar *protocol,
|
||||
gchar *gnc_uri_create_uri (const gchar *scheme,
|
||||
const gchar *hostname,
|
||||
gint32 port,
|
||||
const gchar *username,
|
||||
@ -167,12 +169,12 @@ gchar *gnc_uri_create_uri (const gchar *protocol,
|
||||
* The resulting uri will take either of these forms:
|
||||
* @li @c file:///some/absolute/path ('file' can also be xml or sqlite)
|
||||
* @li @c file://c:\\some\\windows\\path ('file' can also be xml or sqlite)
|
||||
* @li @c protocol://[user[:password]@]hostname[:port]/path
|
||||
* @li @c scheme://[user[:password]@]hostname[:port]/path
|
||||
*
|
||||
* Only the components that are provided will be inserted in the uri. The
|
||||
* allow_password parameter controls if the password should be added to the
|
||||
* returned uri when available.
|
||||
* If no protocol has been provided, 'file' will be used as default protocol.
|
||||
* If no scheme has been provided, 'file' will be used as default scheme.
|
||||
*
|
||||
* The function allocates memory for the uri. The calling function should
|
||||
* free this memory with g_free the uri is no longer needed.
|
||||
@ -189,7 +191,7 @@ gchar *gnc_uri_normalize_uri (const gchar *uri, gboolean allow_password);
|
||||
|
||||
/** Checks if the given uri is a valid uri
|
||||
*
|
||||
* A valid uri is defined by having at least a protocol and a path.
|
||||
* A valid uri is defined by having at least a scheme and a path.
|
||||
* If the uri is not referring to a file on the local file system
|
||||
* a hostname should be set as well.
|
||||
*
|
||||
@ -200,40 +202,42 @@ gchar *gnc_uri_normalize_uri (const gchar *uri, gboolean allow_password);
|
||||
gboolean gnc_uri_is_uri (const gchar *uri);
|
||||
|
||||
|
||||
/** Checks if there is a backend that explicitly stated to handle the given protocol.
|
||||
/** Checks if there is a backend that explicitly stated to handle the given scheme.
|
||||
*
|
||||
* @param protocol The protocol to check
|
||||
* @param scheme The scheme to check
|
||||
*
|
||||
* @return TRUE if at least one backend explicitly handles this protocol, otherwise FALSE
|
||||
* @return TRUE if at least one backend explicitly handles this scheme, otherwise FALSE
|
||||
*/
|
||||
gboolean gnc_uri_is_known_protocol (const gchar *protocol);
|
||||
gboolean gnc_uri_is_known_scheme (const gchar *scheme);
|
||||
|
||||
|
||||
/** Checks if the given protocol is used to refer to a file
|
||||
/** Checks if the given scheme is used to refer to a file
|
||||
* (as opposed to a network service like a database or web url)
|
||||
*
|
||||
* @param protocol The protocol to check
|
||||
* @param scheme The scheme to check
|
||||
*
|
||||
* @return TRUE if the protocol is used with files, FALSE of the protocol
|
||||
* is normally used with network services (database, web url,...)
|
||||
* @return TRUE if the scheme is used with files, FALSE if the scheme
|
||||
* is normally used with network services (database, web url,...).
|
||||
* It will also return FALSE if scheme is NULL.
|
||||
*/
|
||||
gboolean gnc_uri_is_file_protocol (const gchar *protocol);
|
||||
gboolean gnc_uri_is_file_scheme (const gchar *scheme);
|
||||
|
||||
|
||||
/** Checks if the given uri defines a file
|
||||
* (as opposed to a network service like a database or web url)
|
||||
*
|
||||
* @param uri The uri to check
|
||||
*
|
||||
* @return TRUE if the uri is a files, FALSE of the protocol
|
||||
* @return TRUE if the uri is a files, FALSE of the scheme
|
||||
* is normally used with network services (database, web url,...)
|
||||
*/
|
||||
gboolean gnc_uri_is_file_uri (const gchar *uri);
|
||||
|
||||
|
||||
/** Checks if the given uri is either a valid file uri or a local filesystem path
|
||||
*
|
||||
* A valid uri is defined by having at least a protocol and a path.
|
||||
* If the uri is not referring to a file on the local file system
|
||||
* a hostname should be set as well.
|
||||
* A valid file uri is defined by having a file targeting scheme
|
||||
* ('file', 'xml' or 'sqlite3' are accepted) and a non-NULL path.
|
||||
*
|
||||
* @param uri The uri to check
|
||||
*
|
||||
@ -242,6 +246,7 @@ gboolean gnc_uri_is_file_uri (const gchar *uri);
|
||||
*/
|
||||
gboolean gnc_uri_targets_local_fs (const gchar *uri);
|
||||
|
||||
|
||||
/** Adds an extension to the uri if:
|
||||
* * the uri is not empty and file based
|
||||
* * doesn't already have the extension
|
||||
@ -257,6 +262,54 @@ gboolean gnc_uri_targets_local_fs (const gchar *uri);
|
||||
*/
|
||||
gchar *gnc_uri_add_extension ( const gchar *uri, const gchar *extension );
|
||||
|
||||
|
||||
/** @name Deprecated functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** Extracts the protocol from a uri
|
||||
*
|
||||
* @deprecated This function has been deprecated in gnucash 3.4. Please use gnc_uri_get_scheme instead.
|
||||
*
|
||||
* The function allocates memory for the protocol. The calling function should
|
||||
* free this memory with g_free if it no longer needs the string.
|
||||
*
|
||||
* @param uri The uri to extract the protocol from
|
||||
*
|
||||
* @return The protocol for this uri. If the uri didn't have an
|
||||
* explicit protocol, NULL will be returned.
|
||||
*/
|
||||
|
||||
gchar *gnc_uri_get_protocol (const gchar *uri)
|
||||
GNC_DEPRECATED("Please use gnc_uri_get_scheme instead (since 3.4)");
|
||||
|
||||
/** Checks if there is a backend that explicitly stated to handle the given protocol.
|
||||
*
|
||||
* @deprecated This function has been deprecated in gnucash 3.4. Please use gnc_uri_is_known_scheme instead.
|
||||
*
|
||||
* @param protocol The protocol to check
|
||||
*
|
||||
* @return TRUE if at least one backend explicitly handles this protocol, otherwise FALSE
|
||||
*/
|
||||
gboolean gnc_uri_is_known_protocol (const gchar *protocol)
|
||||
GNC_DEPRECATED("Please use gnc_uri_known_scheme instead (since 3.4)");
|
||||
|
||||
|
||||
/** Checks if the given protocol is used to refer to a file
|
||||
* (as opposed to a network service like a database or web url)
|
||||
*
|
||||
* @deprecated This function has been deprecated in gnucash 3.4. Please use gnc_uri_is_file_scheme instead.
|
||||
*
|
||||
* @param protocol The protocol to check
|
||||
*
|
||||
* @return TRUE if the protocol is used with files, FALSE of the protocol
|
||||
* is normally used with network services (database, web url,...)
|
||||
*/
|
||||
gboolean gnc_uri_is_file_protocol (const gchar *protocol)
|
||||
GNC_DEPRECATED("Please use gnc_uri_is_file_scheme instead (since 3.4)");
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* GNCURIUTILS_H_ */
|
||||
/** @} */
|
||||
/** @} */
|
||||
|
@ -230,14 +230,14 @@ test_gnc_uri_get_components()
|
||||
|
||||
/* TEST: gnc_uri_get_protocol */
|
||||
static void
|
||||
test_gnc_uri_get_protocol()
|
||||
test_gnc_uri_get_scheme()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; strs[i].uri != NULL; i++)
|
||||
{
|
||||
gchar *tprotocol = NULL;
|
||||
|
||||
tprotocol = gnc_uri_get_protocol( strs[i].uri );
|
||||
tprotocol = gnc_uri_get_scheme( strs[i].uri );
|
||||
g_assert_cmpstr ( tprotocol, ==, strs[i].protocol );
|
||||
g_free(tprotocol);
|
||||
}
|
||||
@ -293,14 +293,14 @@ test_gnc_uri_normalize_uri()
|
||||
|
||||
/* TEST: gnc_uri_is_file_protocol */
|
||||
static void
|
||||
test_gnc_uri_is_file_protocol()
|
||||
test_gnc_uri_is_file_scheme()
|
||||
{
|
||||
int i;
|
||||
for (i = 0; strs[i].uri != NULL; i++)
|
||||
{
|
||||
gboolean tis_file_protocol;
|
||||
|
||||
tis_file_protocol = gnc_uri_is_file_protocol( strs[i].protocol );
|
||||
tis_file_protocol = gnc_uri_is_file_scheme( strs[i].protocol );
|
||||
g_assert_true ( tis_file_protocol == strs[i].is_file_protocol );
|
||||
}
|
||||
}
|
||||
@ -323,11 +323,11 @@ void
|
||||
test_suite_gnc_uri_utils(void)
|
||||
{
|
||||
GNC_TEST_ADD_FUNC(suitename, "gnc_uri_get_components()", test_gnc_uri_get_components);
|
||||
GNC_TEST_ADD_FUNC(suitename, "gnc_uri_get_protocol()", test_gnc_uri_get_protocol);
|
||||
GNC_TEST_ADD_FUNC(suitename, "gnc_uri_get_scheme()", test_gnc_uri_get_scheme);
|
||||
GNC_TEST_ADD_FUNC(suitename, "gnc_uri_get_path()", test_gnc_uri_get_path);
|
||||
GNC_TEST_ADD_FUNC(suitename, "gnc_uri_create_uri()", test_gnc_uri_create_uri);
|
||||
GNC_TEST_ADD_FUNC(suitename, "gnc_uri_normalize_uri()", test_gnc_uri_normalize_uri);
|
||||
GNC_TEST_ADD_FUNC(suitename, "gnc_uri_is_file_protocol()", test_gnc_uri_is_file_protocol);
|
||||
GNC_TEST_ADD_FUNC(suitename, "gnc_uri_is_file_scheme()", test_gnc_uri_is_file_scheme);
|
||||
GNC_TEST_ADD_FUNC(suitename, "gnc_uri_is_file_uri()", test_gnc_uri_is_file_uri);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user