[gnome-commander] Use glib functions to parse a given URI for remote connections
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander] Use glib functions to parse a given URI for remote connections
- Date: Tue, 28 Sep 2021 19:01:29 +0000 (UTC)
commit 6e963ad24b03a76d600b70d066658cdf52ad2986
Author: Uwe Scholz <u scholz83 gmx de>
Date: Sat Sep 25 23:17:01 2021 +0200
Use glib functions to parse a given URI for remote connections
Increase the needed glib version to 2.66 for this
configure.ac | 2 +-
src/gnome-cmd-con-remote.cc | 35 +++++++++++++++++++++--------------
src/gnome-cmd-con.h | 39 +++++++++++++++++++++++++++++++++------
3 files changed, 55 insertions(+), 21 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f7afb6d2..cbc91842 100644
--- a/configure.ac
+++ b/configure.ac
@@ -34,7 +34,7 @@ dnl ===================
dnl Check for libraries
dnl ===================
-GLIB_REQ=2.62.0
+GLIB_REQ=2.66.0
GMODULE_REQ=2.0.0
GTK_REQ=2.24.0
GNOMEVFS_REQ=2.0.0
diff --git a/src/gnome-cmd-con-remote.cc b/src/gnome-cmd-con-remote.cc
index 8f559a40..fd61ac67 100644
--- a/src/gnome-cmd-con-remote.cc
+++ b/src/gnome-cmd-con-remote.cc
@@ -271,43 +271,50 @@ GtkType gnome_cmd_con_remote_get_type ()
*/
GnomeCmdConRemote *gnome_cmd_con_remote_new (const gchar *alias, const string &uri_str,
GnomeCmdCon::Authentication auth)
{
- gchar *canonical_uri = gnome_vfs_make_uri_canonical (uri_str.c_str());
-
- auto gFile = g_file_new_for_uri(canonical_uri);
-
auto server = static_cast<GnomeCmdConRemote*> (g_object_new (GNOME_CMD_TYPE_CON_REMOTE, nullptr));
g_return_val_if_fail (server != nullptr, nullptr);
GError *error = nullptr;
- auto uri = g_file_get_uri(gFile);
- auto gSocketConnectable = g_network_address_parse_uri (uri, 0, &error);
+
+ gchar *host = nullptr;
+ gint port = 0;
+ gchar *path = nullptr;
+
+ g_uri_split (
+ uri_str.c_str(),
+ G_URI_FLAGS_NONE,
+ nullptr, //scheme
+ nullptr, //userinfo
+ &host,
+ &port,
+ &path,
+ nullptr, //query
+ nullptr, //fragment
+ &error
+ );
if (error)
{
- g_warning("gnome_cmd_con_remote_new: g_network_address_parse_uri error: %s", error->message);
+ g_warning("gnome_cmd_con_remote_new - g_uri_split error: %s", error->message);
g_error_free(error);
return nullptr;
}
- const gchar *host = g_network_address_get_hostname ((GNetworkAddress*) gSocketConnectable); // do not
g_free
- auto port = g_network_address_get_port ((GNetworkAddress*) gSocketConnectable); // do not g_free
- auto path = g_file_get_path(gFile);
-
GnomeCmdCon *con = GNOME_CMD_CON (server);
gnome_cmd_con_set_alias (con, alias);
- gnome_cmd_con_set_uri (con, canonical_uri);
+ gnome_cmd_con_set_uri (con, uri_str.c_str());
gnome_cmd_con_set_host_name (con, host);
gnome_cmd_con_set_port (con, port);
gnome_cmd_con_set_root_path (con, path);
gnome_cmd_con_remote_set_host_name (server, host);
- con->method = gnome_cmd_con_get_scheme (gFile);
+ con->method = gnome_cmd_con_get_scheme (uri_str.c_str());
con->auth = con->method==CON_ANON_FTP ? GnomeCmdCon::NOT_REQUIRED : GnomeCmdCon::SAVE_FOR_SESSION;
g_free (path);
- g_object_unref (gFile);
+ g_free(host);
return server;
}
diff --git a/src/gnome-cmd-con.h b/src/gnome-cmd-con.h
index e4333498..6a58a18e 100644
--- a/src/gnome-cmd-con.h
+++ b/src/gnome-cmd-con.h
@@ -383,14 +383,37 @@ inline gchar *gnome_cmd_con_get_free_space (GnomeCmdCon *con, GnomeCmdDir *dir,
return retval;
}
-inline ConnectionMethodID gnome_cmd_con_get_scheme (GnomeVFSURI *uri)
-{
- const gchar *scheme = gnome_vfs_uri_get_scheme (uri); // do not g_free
- const gchar *user = gnome_vfs_uri_get_user_name (uri); // do not g_free
+inline ConnectionMethodID gnome_cmd_con_get_scheme (const gchar *uriString)
+{
+ gchar *scheme = nullptr;
+ gchar *user = nullptr;
+ GError *error = nullptr;
+
+ g_uri_split_with_user (
+ uriString,
+ G_URI_FLAGS_HAS_PASSWORD,
+ &scheme, //scheme
+ &user, //user
+ nullptr, //password
+ nullptr, //auth_params
+ nullptr, //host
+ nullptr, //port
+ nullptr, //path
+ nullptr, //query
+ nullptr, //fragment
+ &error
+ );
+
+ if(error)
+ {
+ g_warning("gnome_cmd_con_get_scheme - g_uri_split_with_user error: %s", error->message);
+ g_error_free(error);
+ return CON_INVALID;
+ }
- return scheme == nullptr ? CON_INVALID :
+ ConnectionMethodID retValue = scheme == nullptr ? CON_INVALID :
g_str_equal (scheme, "file") ? CON_FILE :
-// g_str_equal (scheme, "ftp") ? (user && g_str_equal (user, "anonymous") ? CON_ANON_FTP :
CON_FTP) :
+ g_str_equal (scheme, "ftp") ? (user && g_str_equal (user, "anonymous") ? CON_ANON_FTP : CON_FTP)
:
g_str_equal (scheme, "ftp") ? CON_FTP :
g_str_equal (scheme, "sftp") ? CON_SSH :
g_str_equal (scheme, "dav") ? CON_DAV :
@@ -399,6 +422,10 @@ inline ConnectionMethodID gnome_cmd_con_get_scheme (GnomeVFSURI *uri)
g_str_equal (scheme, "smb") ? CON_SMB :
#endif
CON_URI;
+
+ g_free(user);
+ g_free(scheme);
+ return retValue;
}
std::string &__gnome_cmd_con_make_uri (std::string &s, const gchar *method, gboolean use_auth, std::string
&server, std::string &port, std::string &folder, std::string &user, std::string &password);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]