From 171d3aeca85824de7aecf6e6c905682ea81655ba Mon Sep 17 00:00:00 2001 From: Vinicius Costa Gomes Date: Fri, 26 Feb 2010 16:32:13 -0300 Subject: [PATCH] obexd: Cleaning up the ftp service Now, all access to session information is done through the proper channels. --- obexd/plugins/ftp.c | 30 +++++++++++++++++++----------- obexd/src/obex.c | 15 ++++++++++++++- obexd/src/obex.h | 4 +++- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c index a98163d38..fe775f455 100644 --- a/obexd/plugins/ftp.c +++ b/obexd/plugins/ftp.c @@ -144,27 +144,32 @@ static const guint8 FTP_TARGET[TARGET_SIZE] = { static const guint8 PCSUITE_WHO[PCSUITE_WHO_SIZE] = { 'P','C',' ','S','u','i','t','e' }; -static gint get_by_type(struct OBEX_session *os, gchar *type) +static gint get_by_type(struct OBEX_session *os, const gchar *type) { + const char *folder = obex_get_folder(os); + const char *capability = obex_get_capability_path(os); + if (type == NULL) return -ENOENT; if (g_str_equal(type, CAP_TYPE)) - return obex_stream_start(os, os->server->capability); + return obex_stream_start(os, capability); if (g_str_equal(type, LST_TYPE)) - return obex_stream_start(os, os->current_folder); + return obex_stream_start(os, folder); return -ENOENT; } -static gint ftp_prepare_get(struct obex_session *os, gchar *file) +static gint ftp_prepare_get(struct OBEX_session *os, gchar *file) { + const char *root_folder = obex_get_root_folder(os); + const char *folder = obex_get_folder(os); gboolean root; - root = g_str_equal(os->server->folder, os->current_folder); + root = g_str_equal(root_folder, folder); - if (!root || !os->server->symlinks) { + if (!root || !obex_get_symlinks(os)) { struct stat dstat; gint err; @@ -190,20 +195,23 @@ static obex_rsp_t ftp_connect(struct OBEX_session *os) static obex_rsp_t ftp_get(struct OBEX_session *os) { + const char *folder = obex_get_folder(os); + const char *type = obex_get_type(os); + const char *name = obex_get_name(os); gint err; gchar *path; - if (os->current_folder == NULL) { + if (folder == NULL) { err = -ENOENT; goto fail; } - err = get_by_type(os, os->type); + err = get_by_type(os, type); if (err < 0) { - if (!os->name) + if (!name) goto fail; - path = g_build_filename(os->current_folder, os->name, NULL); + path = g_build_filename(folder, name, NULL); err = ftp_prepare_get(os, path); @@ -237,7 +245,7 @@ static gint ftp_delete(struct OBEX_session *os) path = g_build_filename(folder, name, NULL); - if (os->driver->remove(path) < 0) + if (obex_remove(os, path) < 0) ret = -errno; g_free(path); diff --git a/obexd/src/obex.c b/obexd/src/obex.c index 958738815..0483c7d60 100644 --- a/obexd/src/obex.c +++ b/obexd/src/obex.c @@ -433,7 +433,7 @@ static void cmd_setpath(struct obex_session *os, os_set_response(obj, rsp); } -int obex_stream_start(struct OBEX_session *os, gchar *filename) +int obex_stream_start(struct OBEX_session *os, const gchar *filename) { gint err; gpointer object; @@ -1142,3 +1142,16 @@ gboolean obex_get_symlinks(struct OBEX_session *os) { return os->server->symlinks; } + +const char *obex_get_capability_path(struct OBEX_session *os) +{ + return os->server->capability; +} + +int obex_remove(struct OBEX_session *os, const char *path) +{ + if (os->driver == NULL) + return -EINVAL; + + return os->driver->remove(path); +} diff --git a/obexd/src/obex.h b/obexd/src/obex.h index 434665706..72b031991 100644 --- a/obexd/src/obex.h +++ b/obexd/src/obex.h @@ -89,7 +89,7 @@ void obex_connect_cb(GIOChannel *io, GError *err, gpointer user_data); gint obex_session_start(GIOChannel *io, struct server *server); struct obex_session *obex_get_session(gpointer object); -int obex_stream_start(struct OBEX_session *os, gchar *filename); +int obex_stream_start(struct OBEX_session *os, const gchar *filename); gint obex_prepare_put(struct obex_session *os); const char *obex_get_name(struct OBEX_session *os); void obex_set_name(struct OBEX_session *os, const gchar *name); @@ -99,6 +99,8 @@ const char *obex_get_folder(struct OBEX_session *os); void obex_set_folder(struct OBEX_session *os, const char *folder); const char *obex_get_root_folder(struct OBEX_session *os); gboolean obex_get_symlinks(struct OBEX_session *os); +const char *obex_get_capability_path(struct OBEX_session *os); +int obex_remove(struct OBEX_session *os, const char *path); void server_free(struct server *server); int tty_init(gint service, const gchar *folder, const gchar *capability, -- 2.47.3