gnucash/src/core-utils/gnc-uri-utils.h

206 lines
8.2 KiB
C
Raw Normal View History

Use a normalized uri format internally to refer to data stores. Data stores for GC can be a file (xml or sqlite3) or a database one some server (mysql or postgres). Wherever it makes sense internally, data stores will be referred to via a normalized uri: protocol://user:password@host:port/path Depending on the context and story type some of these parts are optional or unused. To achieve this, a new utility interface has been setup: gnc_uri_<xxx>_<yyy> that can be used to manipulate the uris or convert from non-normalized formats to normalized and back. For example, when the user selects a file in the Open or Save As dialog, gnc_uri_get_normalized_uri will convert the file into a normalized uri. Or when the actual filename is needed this can be extracted with gnc_uri_get_path. You can also test if a uri defines a file or something else with gnc_uri_is_file_uri. For the complete documentation, see src/core-utils/gnc-uri-uitls.h This commit installs gnc-uri-utils and modifies the source where it makes sense to use its convenience functions. This concerns all functions that had to deal with file access in some way or another, the history module and the functions that generate the history menu list and the window titles. Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases. xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality. xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path is always returned (in case of a file uri, not for db uris). But it has been renamed to gnc_resolve_file_path to be more consistent with the other functions. Lastly, this commit also adds a first implementation to work with a keyring to store and retrieve passwords, althoug git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
/*
* gnc-uri-utils.h -- utility functions to convert uri in separate
* components and back.
*
* Copyright (C) 2010 Geert Janssens <janssens.geert@telenet.be>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, contact:
*
* Free Software Foundation Voice: +1-617-542-5942
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
* Boston, MA 02110-1301, USA gnu@gnu.org
*/
/** @addtogroup Utils Utility functions
@{ */
/** @addtogroup UtilUri Uri conversion
* @{ */
/** @file gnc-uri-utils.h
* @brief Utility functions for convert uri in separate components and back
* @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
* to compose a uri from these separate components.
*
*/
#ifndef GNCURIUTILS_H_
#define GNCURIUTILS_H_
/** Converts a uri in separate components.
*
* Uri's can take any of the following forms:
*
* @li @c /some/filesystem/path A simple file system path (unix style)
* @li @c c:\\some\\windows\\path A simple file system path (Windows style)
Use a normalized uri format internally to refer to data stores. Data stores for GC can be a file (xml or sqlite3) or a database one some server (mysql or postgres). Wherever it makes sense internally, data stores will be referred to via a normalized uri: protocol://user:password@host:port/path Depending on the context and story type some of these parts are optional or unused. To achieve this, a new utility interface has been setup: gnc_uri_<xxx>_<yyy> that can be used to manipulate the uris or convert from non-normalized formats to normalized and back. For example, when the user selects a file in the Open or Save As dialog, gnc_uri_get_normalized_uri will convert the file into a normalized uri. Or when the actual filename is needed this can be extracted with gnc_uri_get_path. You can also test if a uri defines a file or something else with gnc_uri_is_file_uri. For the complete documentation, see src/core-utils/gnc-uri-uitls.h This commit installs gnc-uri-utils and modifies the source where it makes sense to use its convenience functions. This concerns all functions that had to deal with file access in some way or another, the history module and the functions that generate the history menu list and the window titles. Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases. xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality. xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path is always returned (in case of a file uri, not for db uris). But it has been renamed to gnc_resolve_file_path to be more consistent with the other functions. Lastly, this commit also adds a first implementation to work with a keyring to store and retrieve passwords, althoug git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
* @li @c proto://[[username[:password]@]hostname[:port]]/path (universal uri)
*
* In the last form, anything in square brackets is optional.
*
* The function allocates memory for each of the components that it finds
* in the uri. The calling function should free this memory with g_free
* if the items are no longer needed.
*
* @param uri The uri to convert
*
* @param protocol The protocol for this uri. If the uri didn't have an
* explicit protocol, 'file' will be the assumed protocol and hence what
* will be returned.
* @param hostname The host name of the server to connect to. In case of
* the 'file' protocol, this will be NULL
* @param port An optional port to connect to or 0 if the default port is to
* be used. For the 'file' protocol this is always 0 as well.
* @param username Optional user name found in this uri or NULL if none is found.
* @param password Optional password found in this uri or NULL if none is found.
* @param path The path found in this uri. Note that if the protocol is a file based
Use a normalized uri format internally to refer to data stores. Data stores for GC can be a file (xml or sqlite3) or a database one some server (mysql or postgres). Wherever it makes sense internally, data stores will be referred to via a normalized uri: protocol://user:password@host:port/path Depending on the context and story type some of these parts are optional or unused. To achieve this, a new utility interface has been setup: gnc_uri_<xxx>_<yyy> that can be used to manipulate the uris or convert from non-normalized formats to normalized and back. For example, when the user selects a file in the Open or Save As dialog, gnc_uri_get_normalized_uri will convert the file into a normalized uri. Or when the actual filename is needed this can be extracted with gnc_uri_get_path. You can also test if a uri defines a file or something else with gnc_uri_is_file_uri. For the complete documentation, see src/core-utils/gnc-uri-uitls.h This commit installs gnc-uri-utils and modifies the source where it makes sense to use its convenience functions. This concerns all functions that had to deal with file access in some way or another, the history module and the functions that generate the history menu list and the window titles. Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases. xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality. xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path is always returned (in case of a file uri, not for db uris). But it has been renamed to gnc_resolve_file_path to be more consistent with the other functions. Lastly, this commit also adds a first implementation to work with a keyring to store and retrieve passwords, althoug git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
* protocol, the path will be converted to an absolute path.
*
*/
void gnc_uri_get_components (const gchar *uri,
gchar **protocol,
gchar **hostname,
guint32 port,
gchar **username,
gchar **password,
gchar **path);
/** Extracts the protocol from a uri
*
* Uri's can take any of the following forms:
*
* @li @c /some/filesystem/path A simple file system path (unix style)
* @li @c c:\\some\\windows\\path A simple file system path (Windows style)
Use a normalized uri format internally to refer to data stores. Data stores for GC can be a file (xml or sqlite3) or a database one some server (mysql or postgres). Wherever it makes sense internally, data stores will be referred to via a normalized uri: protocol://user:password@host:port/path Depending on the context and story type some of these parts are optional or unused. To achieve this, a new utility interface has been setup: gnc_uri_<xxx>_<yyy> that can be used to manipulate the uris or convert from non-normalized formats to normalized and back. For example, when the user selects a file in the Open or Save As dialog, gnc_uri_get_normalized_uri will convert the file into a normalized uri. Or when the actual filename is needed this can be extracted with gnc_uri_get_path. You can also test if a uri defines a file or something else with gnc_uri_is_file_uri. For the complete documentation, see src/core-utils/gnc-uri-uitls.h This commit installs gnc-uri-utils and modifies the source where it makes sense to use its convenience functions. This concerns all functions that had to deal with file access in some way or another, the history module and the functions that generate the history menu list and the window titles. Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases. xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality. xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path is always returned (in case of a file uri, not for db uris). But it has been renamed to gnc_resolve_file_path to be more consistent with the other functions. Lastly, this commit also adds a first implementation to work with a keyring to store and retrieve passwords, althoug git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
* @li @c proto://[[username[:password]@]hostname[:port]]/path (universal uri)
*
* In the last form, anything in square brackets is optional.
*
* 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, 'file' will be returned as protocol.
*/
gchar *gnc_uri_get_protocol (const gchar *uri);
/** Extracts the path part from a uri
*
* Uri's can take any of the following forms:
*
* @li @c /some/filesystem/path A simple file system path (unix style)
* @li @c c:\\some\\windows\\path A simple file system path (Windows style)
Use a normalized uri format internally to refer to data stores. Data stores for GC can be a file (xml or sqlite3) or a database one some server (mysql or postgres). Wherever it makes sense internally, data stores will be referred to via a normalized uri: protocol://user:password@host:port/path Depending on the context and story type some of these parts are optional or unused. To achieve this, a new utility interface has been setup: gnc_uri_<xxx>_<yyy> that can be used to manipulate the uris or convert from non-normalized formats to normalized and back. For example, when the user selects a file in the Open or Save As dialog, gnc_uri_get_normalized_uri will convert the file into a normalized uri. Or when the actual filename is needed this can be extracted with gnc_uri_get_path. You can also test if a uri defines a file or something else with gnc_uri_is_file_uri. For the complete documentation, see src/core-utils/gnc-uri-uitls.h This commit installs gnc-uri-utils and modifies the source where it makes sense to use its convenience functions. This concerns all functions that had to deal with file access in some way or another, the history module and the functions that generate the history menu list and the window titles. Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases. xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality. xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path is always returned (in case of a file uri, not for db uris). But it has been renamed to gnc_resolve_file_path to be more consistent with the other functions. Lastly, this commit also adds a first implementation to work with a keyring to store and retrieve passwords, althoug git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
* @li @c proto://[[username[:password]@]hostname[:port]]/path (universal uri)
*
* In the last form, anything in square brackets is optional.
*
* The function allocates memory for the path. The calling function should
* free this memory with g_free if it no longer needs the string.
*
* @param uri The uri to extract the path part from
*
* @return The protocol for this uri, or NULL if no path could be extracted.
*/
gchar *gnc_uri_get_path (const gchar *uri);
/** Composes a normalized uri starting from its separate components.
*
* 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
*
* 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.
*
* The function allocates memory for 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
* 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').
* @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',
* 'sqlite').
* @param username Optional user name to set in the uri or NULL otherwise. This will
Use a normalized uri format internally to refer to data stores. Data stores for GC can be a file (xml or sqlite3) or a database one some server (mysql or postgres). Wherever it makes sense internally, data stores will be referred to via a normalized uri: protocol://user:password@host:port/path Depending on the context and story type some of these parts are optional or unused. To achieve this, a new utility interface has been setup: gnc_uri_<xxx>_<yyy> that can be used to manipulate the uris or convert from non-normalized formats to normalized and back. For example, when the user selects a file in the Open or Save As dialog, gnc_uri_get_normalized_uri will convert the file into a normalized uri. Or when the actual filename is needed this can be extracted with gnc_uri_get_path. You can also test if a uri defines a file or something else with gnc_uri_is_file_uri. For the complete documentation, see src/core-utils/gnc-uri-uitls.h This commit installs gnc-uri-utils and modifies the source where it makes sense to use its convenience functions. This concerns all functions that had to deal with file access in some way or another, the history module and the functions that generate the history menu list and the window titles. Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases. xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality. xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path is always returned (in case of a file uri, not for db uris). But it has been renamed to gnc_resolve_file_path to be more consistent with the other functions. Lastly, this commit also adds a first implementation to work with a keyring to store and retrieve passwords, althoug git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
* be ignored for the 'file' type protocols ('file', 'xml', 'sqlite').
* @param password Optional password to set in the uri or NULL otherwise. This will
Use a normalized uri format internally to refer to data stores. Data stores for GC can be a file (xml or sqlite3) or a database one some server (mysql or postgres). Wherever it makes sense internally, data stores will be referred to via a normalized uri: protocol://user:password@host:port/path Depending on the context and story type some of these parts are optional or unused. To achieve this, a new utility interface has been setup: gnc_uri_<xxx>_<yyy> that can be used to manipulate the uris or convert from non-normalized formats to normalized and back. For example, when the user selects a file in the Open or Save As dialog, gnc_uri_get_normalized_uri will convert the file into a normalized uri. Or when the actual filename is needed this can be extracted with gnc_uri_get_path. You can also test if a uri defines a file or something else with gnc_uri_is_file_uri. For the complete documentation, see src/core-utils/gnc-uri-uitls.h This commit installs gnc-uri-utils and modifies the source where it makes sense to use its convenience functions. This concerns all functions that had to deal with file access in some way or another, the history module and the functions that generate the history menu list and the window titles. Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases. xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality. xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path is always returned (in case of a file uri, not for db uris). But it has been renamed to gnc_resolve_file_path to be more consistent with the other functions. Lastly, this commit also adds a first implementation to work with a keyring to store and retrieve passwords, althoug git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
* be ignored for the 'file' type protocols ('file', 'xml', 'sqlite').
* @param path The path to set in the uri.
Use a normalized uri format internally to refer to data stores. Data stores for GC can be a file (xml or sqlite3) or a database one some server (mysql or postgres). Wherever it makes sense internally, data stores will be referred to via a normalized uri: protocol://user:password@host:port/path Depending on the context and story type some of these parts are optional or unused. To achieve this, a new utility interface has been setup: gnc_uri_<xxx>_<yyy> that can be used to manipulate the uris or convert from non-normalized formats to normalized and back. For example, when the user selects a file in the Open or Save As dialog, gnc_uri_get_normalized_uri will convert the file into a normalized uri. Or when the actual filename is needed this can be extracted with gnc_uri_get_path. You can also test if a uri defines a file or something else with gnc_uri_is_file_uri. For the complete documentation, see src/core-utils/gnc-uri-uitls.h This commit installs gnc-uri-utils and modifies the source where it makes sense to use its convenience functions. This concerns all functions that had to deal with file access in some way or another, the history module and the functions that generate the history menu list and the window titles. Note that gnc-uri-utils replaces xaccResolveFilePath and xaccResolveUrl in all cases. xaccResolveUrl has been removed, because gnc-uri-utils fully replaces its functionality. xaccResolveFilePath is used internally in gnc-uri-utils to ensure an absolute path is always returned (in case of a file uri, not for db uris). But it has been renamed to gnc_resolve_file_path to be more consistent with the other functions. Lastly, this commit also adds a first implementation to work with a keyring to store and retrieve passwords, althoug git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18842 57a11ea4-9604-0410-9ed3-97b8803252fd
2010-03-05 14:15:31 -06:00
*
* @return The normalized uri.
*/
gchar *gnc_uri_create_uri (const gchar *protocol,
const gchar *hostname,
guint32 port,
const gchar *username,
const gchar *password,
const gchar *path);
/** Composes a normalized uri starting from any uri (filename, db spec,...).
*
* 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
*
* 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.
*
* The function allocates memory for for the uri. The calling function should
* free this memory with g_free the uri is no longer needed.
*
* @param uri The uri that schould be converted into a normalized uri
* @param allow_password If set to TRUE, the normalized uri and the input uri
* has a password, this passworld will also be set in the normalized uri.
* Otherwise no password will be set in the normalized uri.
*
* @return The normalized uri.
*/
gchar *gnc_uri_normalize_uri (const gchar *uri, gboolean allow_password);
/** Checks if the given protocol 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
*
* @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);
/** 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
* is normally used with network services (database, web url,...)
*/
gboolean gnc_uri_is_file_uri (const gchar *uri);
#endif /* GNCURIUTILS_H_ */
/** @} */
/** @} */