Diff between 0c2498c8706c82d462904f830245d5dde2599285 and 171d3aeca85824de7aecf6e6c905682ea81655ba

Changed Files

File Additions Deletions Status
obexd/plugins/ftp.c +19 -11 modified
obexd/src/obex.c +14 -1 modified
obexd/src/obex.h +3 -1 modified

Full Patch

diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c
index a98163d..fe775f4 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 9587388..0483c7d 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 4346657..72b0319 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,