Diff between 1c55fb8d7b67ac6ead97c01023b9a0fb3709461d and e539764caa99d648d2e9c9b78f0add432aff5caf

Changed Files

File Additions Deletions Status
obexd/src/ftp.c +33 -4 modified
obexd/src/obex.c +43 -0 modified
obexd/src/obex.h +2 -0 modified
obexd/src/opp.c +3 -36 modified

Full Patch

diff --git a/obexd/src/ftp.c b/obexd/src/ftp.c
index 54eff98..03cecb0 100644
--- a/obexd/src/ftp.c
+++ b/obexd/src/ftp.c
@@ -46,7 +46,7 @@
 
 #include "logging.h"
 #include "obex.h"
-#include "logging.h"
+#include "dbus.h"
 
 #define LST_TYPE "x-obex/folder-listing"
 #define CAP_TYPE "x-obex/capability"
@@ -233,12 +233,41 @@ fail:
 	return;
 }
 
-void ftp_put(obex_t *obex, obex_object_t *obj)
+gint ftp_chkput(obex_t *obex, obex_object_t *obj)
 {
-	OBEX_ObjectSetRsp(obj, OBEX_RSP_NOT_IMPLEMENTED,
-			OBEX_RSP_NOT_IMPLEMENTED);
+	struct obex_session *os;
+
+	os = OBEX_GetUserData(obex);
+	if (os == NULL)
+		return -EINVAL;
+
+	if (!os->size)
+		return -EINVAL;
+
+	return os_prepare_put(os);
 }
 
+
+void ftp_put(obex_t *obex, obex_object_t *obj)
+{
+	struct obex_session *os;
+
+	os = OBEX_GetUserData(obex);
+	if (os == NULL)
+		return;
+
+	if (os->current_folder == NULL) {
+		OBEX_ObjectSetRsp(obj, OBEX_RSP_FORBIDDEN, OBEX_RSP_FORBIDDEN);
+		return;
+	}
+
+	if (os->name == NULL) {
+		OBEX_ObjectSetRsp(obj, OBEX_RSP_BAD_REQUEST, OBEX_RSP_BAD_REQUEST);
+		return;
+	}
+
+	OBEX_ObjectSetRsp(obj, OBEX_RSP_CONTINUE, OBEX_RSP_SUCCESS);
+}
 void ftp_setpath(obex_t *obex, obex_object_t *obj)
 {
 	struct obex_session *os;
diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 6b34a8c..d4dc3bf 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
@@ -78,6 +78,7 @@ struct obex_commands ftp = {
 	.get		= ftp_get,
 	.put		= ftp_put,
 	.setpath	= ftp_setpath,
+	.chkput		= ftp_chkput,
 };
 
 static void os_reset_session(struct obex_session *os)
@@ -450,6 +451,48 @@ add_header:
 	return len;
 }
 
+gint os_prepare_put(struct obex_session *os)
+{
+	gchar *path;
+	gint len;
+
+	path = g_build_filename(os->current_folder, os->name, NULL);
+
+	os->fd = open(path, O_WRONLY | O_CREAT, 0600);
+	if (os->fd < 0) {
+		error("open(%s): %s (%d)", path, strerror(errno), errno);
+		g_free(path);
+		return -EPERM;
+	}
+
+	g_free(path);
+
+	emit_transfer_started(os->cid);
+
+	if (!os->buf) {
+		debug("PUT request checked, no buffered data");
+		return 0;
+	}
+
+	len = 0;
+	while (len < os->offset) {
+		gint w;
+
+		w = write(os->fd, os->buf + len, os->offset - len);
+		if (w < 0) {
+			gint err = errno;
+			if (err == EINTR)
+				continue;
+			else
+				return -err;
+		}
+
+		len += w;
+	}
+
+	return 0;
+}
+
 static gint obex_read(struct obex_session *os,
 			obex_t *obex, obex_object_t *obj)
 {
diff --git a/obexd/src/obex.h b/obexd/src/obex.h
index c7dc93f..1e74168 100644
--- a/obexd/src/obex.h
+++ b/obexd/src/obex.h
@@ -73,5 +73,7 @@ void opp_get(obex_t *obex, obex_object_t *obj);
 void ftp_get(obex_t *obex, obex_object_t *obj);
 void ftp_put(obex_t *obex, obex_object_t *obj);
 void ftp_setpath(obex_t *obex, obex_object_t *obj);
+gint ftp_chkput(obex_t *obex, obex_object_t *obj);
 
 gboolean os_prepare_get(struct obex_session *os, gchar *file, guint32 *size);
+gint os_prepare_put(struct obex_session *os);
diff --git a/obexd/src/opp.c b/obexd/src/opp.c
index 70e6fe6..6c674b3 100644
--- a/obexd/src/opp.c
+++ b/obexd/src/opp.c
@@ -51,8 +51,8 @@
 gint opp_chkput(obex_t *obex, obex_object_t *obj)
 {
 	struct obex_session *os;
-	gchar *new_folder, *new_name, *path;
-	gint32 time, len = 0;
+	gchar *new_folder, *new_name;
+	gint32 time;
 	gint ret;
 
 	os = OBEX_GetUserData(obex);
@@ -86,40 +86,7 @@ gint opp_chkput(obex_t *obex, obex_object_t *obj)
 	}
 
 skip_auth:
-	path = g_build_filename(os->current_folder, os->name, NULL);
-
-	os->fd = open(path, O_WRONLY | O_CREAT, 0600);
-	if (os->fd < 0) {
-		error("open(%s): %s (%d)", path, strerror(errno), errno);
-		g_free(path);
-		return -EPERM;
-	}
-
-	g_free(path);
-
-	emit_transfer_started(os->cid);
-
-	if (!os->buf) {
-		debug("PUT request authorized, no buffered data");
-		return 0;
-	}
-
-	while (len < os->offset) {
-		gint w;
-
-		w = write(os->fd, os->buf + len, os->offset - len);
-		if (w < 0) {
-			gint err = errno;
-			if (err == EINTR)
-				continue;
-			else
-				return -err;
-		}
-
-		len += w;
-	}
-
-	return 0;
+	return os_prepare_put(os);
 }
 
 void opp_put(obex_t *obex, obex_object_t *obj)