From 0c2498c8706c82d462904f830245d5dde2599285 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Fri, 26 Feb 2010 15:51:54 -0300 Subject: [PATCH] obexd: Cleanup of check put function of OBEX service driver --- obexd/plugins/ftp.c | 14 +++----------- obexd/plugins/opp.c | 31 +++++++++---------------------- obexd/plugins/pbap.c | 2 +- obexd/src/dbus.h | 9 +++------ obexd/src/manager.c | 18 ++++++++++-------- obexd/src/obex.c | 22 +++++++++++++++------- obexd/src/obex.h | 3 ++- obexd/src/service.h | 2 +- 8 files changed, 44 insertions(+), 57 deletions(-) diff --git a/obexd/plugins/ftp.c b/obexd/plugins/ftp.c index 82cb70833..a98163d38 100644 --- a/obexd/plugins/ftp.c +++ b/obexd/plugins/ftp.c @@ -245,21 +245,13 @@ static gint ftp_delete(struct OBEX_session *os) return ret; } -static gint ftp_chkput(obex_t *obex, obex_object_t *obj) +static gint ftp_chkput(struct OBEX_session *os) { - struct obex_session *os; - os = OBEX_GetUserData(obex); - if (os == NULL) - return -EINVAL; - - if (!os->name) - return -EINVAL; - - if (os->size == OBJECT_SIZE_DELETE) + if (obex_get_size(os) == OBJECT_SIZE_DELETE) return 0; - return os_prepare_put(os); + return obex_prepare_put(os); } static obex_rsp_t ftp_put(struct OBEX_session *os) diff --git a/obexd/plugins/opp.c b/obexd/plugins/opp.c index 2df3d12cd..0a8d9c7d9 100644 --- a/obexd/plugins/opp.c +++ b/obexd/plugins/opp.c @@ -105,49 +105,36 @@ static void opp_progress(struct OBEX_session *os) manager_emit_transfer_progress(os); } -static gint opp_chkput(obex_t *obex, obex_object_t *obj) +static gint opp_chkput(struct OBEX_session *os) { - struct obex_session *os; gchar *new_folder, *new_name; gint32 time; gint ret; - os = OBEX_GetUserData(obex); - if (os == NULL) - return -EINVAL; - - if (!os->name) - return -EINVAL; - - if (os->size == OBJECT_SIZE_DELETE) + if (obex_get_size(os) == OBJECT_SIZE_DELETE) return -EINVAL; if (os->server->auto_accept) goto skip_auth; time = 0; - ret = request_authorization(os->cid, OBEX_GetFD(obex), - os->name ? os->name : "", - os->type ? os->type : "", - os->size, time, &new_folder, - &new_name); - + ret = manager_request_authorization(os, time, &new_folder, &new_name); if (ret < 0) return -EPERM; if (new_folder) { - g_free(os->current_folder); - os->current_folder = new_folder; + obex_set_folder(os, new_folder); + g_free(new_folder); } if (new_name) { - g_free(os->name); - os->name = new_name; + obex_set_name(os, new_name); + g_free(new_name); } skip_auth: - emit_transfer_started(os->cid); - return os_prepare_put(os); + manager_emit_transfer_started(os); + return obex_prepare_put(os); } static obex_rsp_t opp_put(struct OBEX_session *os) diff --git a/obexd/plugins/pbap.c b/obexd/plugins/pbap.c index 90c427f4c..53d4a9c22 100644 --- a/obexd/plugins/pbap.c +++ b/obexd/plugins/pbap.c @@ -535,7 +535,7 @@ static void pbap_disconnect(struct OBEX_session *os) manager_unregister_session(os); } -static gint pbap_chkput(obex_t *obex, obex_object_t *obj) +static gint pbap_chkput(struct OBEX_session *os) { /* Rejects all PUTs */ return -EINVAL; diff --git a/obexd/src/dbus.h b/obexd/src/dbus.h index 965a66df8..288ef3340 100644 --- a/obexd/src/dbus.h +++ b/obexd/src/dbus.h @@ -29,15 +29,9 @@ #define OPENOBEX_MANAGER_INTERFACE OPENOBEX_SERVICE ".Manager" #define ERROR_INTERFACE OPENOBEX_SERVICE ".Error" -void emit_transfer_started(guint32 id); - void emit_transfer_progress(guint32 id, guint32 total, guint32 transfered); -int request_authorization(gint32 cid, int fd, const gchar *filename, - const gchar *type, gint32 length, gint32 time, - gchar **new_folder, gchar **new_name); - void register_record(struct server *server, gpointer user_data); gint request_service_authorization(struct server *server, GIOChannel *io, @@ -47,7 +41,10 @@ void manager_register_session(struct OBEX_session *os); void manager_unregister_session(struct OBEX_session *os); void manager_register_transfer(struct OBEX_session *os); void manager_unregister_transfer(struct OBEX_session *os); +void manager_emit_transfer_started(struct OBEX_session *os); void manager_emit_transfer_progress(struct OBEX_session *os); void manager_emit_transfer_completed(struct OBEX_session *os); +int manager_request_authorization(struct OBEX_session *os, gint32 time, + gchar **new_folder, gchar **new_name); DBusConnection *obex_dbus_get_connection(void); diff --git a/obexd/src/manager.c b/obexd/src/manager.c index fd235374c..f8c0c98d0 100644 --- a/obexd/src/manager.c +++ b/obexd/src/manager.c @@ -580,9 +580,9 @@ void manager_cleanup(void) dbus_connection_unref(connection); } -void emit_transfer_started(guint32 id) +void manager_emit_transfer_started(struct OBEX_session *os) { - gchar *path = g_strdup_printf("/transfer%u", id); + gchar *path = g_strdup_printf("/transfer%u", os->cid); g_dbus_emit_signal(connection, OPENOBEX_MANAGER_PATH, OPENOBEX_MANAGER_INTERFACE, "TransferStarted", @@ -712,9 +712,8 @@ static gboolean auth_error(GIOChannel *io, GIOCondition cond, return FALSE; } -int request_authorization(gint32 cid, int fd, const gchar *filename, - const gchar *type, gint32 length, gint32 time, - gchar **new_folder, gchar **new_name) +int manager_request_authorization(struct OBEX_session *os, gint32 time, + gchar **new_folder, gchar **new_name) { DBusMessage *msg; DBusPendingCall *call; @@ -723,8 +722,10 @@ int request_authorization(gint32 cid, int fd, const gchar *filename, socklen_t addrlen; gchar address[18]; const gchar *bda = address; + const gchar *filename = (os->name ? os->name : ""); + const gchar *type = (os->type ? os->type : ""); gchar *path; - guint watch; + guint watch, fd; gboolean got_reply; if (!agent) @@ -739,12 +740,13 @@ int request_authorization(gint32 cid, int fd, const gchar *filename, memset(&addr, 0, sizeof(addr)); addrlen = sizeof(addr); + fd = OBEX_GetFD(os->obex); if (getpeername(fd, (struct sockaddr *) &addr, &addrlen) < 0) return -errno; ba2str(&addr.rc_bdaddr, address); - path = g_strdup_printf("/transfer%d", cid); + path = g_strdup_printf("/transfer%d", os->cid); msg = dbus_message_new_method_call(agent->bus_name, agent->path, "org.openobex.Agent", "Authorize"); @@ -754,7 +756,7 @@ int request_authorization(gint32 cid, int fd, const gchar *filename, DBUS_TYPE_STRING, &bda, DBUS_TYPE_STRING, &filename, DBUS_TYPE_STRING, &type, - DBUS_TYPE_INT32, &length, + DBUS_TYPE_INT32, &os->size, DBUS_TYPE_INT32, &time, DBUS_TYPE_INVALID); diff --git a/obexd/src/obex.c b/obexd/src/obex.c index addfc2a90..958738815 100644 --- a/obexd/src/obex.c +++ b/obexd/src/obex.c @@ -516,7 +516,7 @@ add_header: return len; } -gint os_prepare_put(struct obex_session *os) +gint obex_prepare_put(struct obex_session *os) { gchar *path; gint len; @@ -657,7 +657,7 @@ static gboolean check_put(obex_t *obex, obex_object_t *obj) obex_headerdata_t hd; guint hlen; guint8 hi; - int ret; + gint ret; os = OBEX_GetUserData(obex); @@ -740,14 +740,14 @@ static gboolean check_put(obex_t *obex, obex_object_t *obj) if (!os->service->chkput) goto done; - ret = os->service->chkput(obex, obj); - switch (ret) { - case 0: - break; - case -EINVAL: + if (!os->name) { OBEX_ObjectSetRsp(obj, OBEX_RSP_BAD_REQUEST, OBEX_RSP_BAD_REQUEST); return FALSE; + } + + ret = os->service->chkput(os); + switch (ret) { case -EPERM: OBEX_ObjectSetRsp(obj, OBEX_RSP_FORBIDDEN, OBEX_RSP_FORBIDDEN); return FALSE; @@ -761,6 +761,7 @@ static gboolean check_put(obex_t *obex, obex_object_t *obj) OBEX_ObjectSetRsp(obj, OBEX_RSP_INTERNAL_SERVER_ERROR, OBEX_RSP_INTERNAL_SERVER_ERROR); return FALSE; + } if (os->size == OBJECT_SIZE_DELETE || os->size == OBJECT_SIZE_UNKNOWN) { @@ -1103,6 +1104,13 @@ const char *obex_get_name(struct OBEX_session *os) return os->name; } +void obex_set_name(struct OBEX_session *os, const gchar *name) +{ + g_free(os->name); + + os->name = (name ? g_strdup(name) : NULL); +} + ssize_t obex_get_size(struct OBEX_session *os) { return os->size; diff --git a/obexd/src/obex.h b/obexd/src/obex.h index d35234921..434665706 100644 --- a/obexd/src/obex.h +++ b/obexd/src/obex.h @@ -90,8 +90,9 @@ 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); -gint os_prepare_put(struct obex_session *os); +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); ssize_t obex_get_size(struct OBEX_session *os); const char *obex_get_type(struct OBEX_session *os); const char *obex_get_folder(struct OBEX_session *os); diff --git a/obexd/src/service.h b/obexd/src/service.h index 8e625fce4..4bd78fe13 100644 --- a/obexd/src/service.h +++ b/obexd/src/service.h @@ -36,7 +36,7 @@ struct obex_service_driver { void (*progress) (struct OBEX_session *os); obex_rsp_t (*get) (struct OBEX_session *os); obex_rsp_t (*put) (struct OBEX_session *os); - gint (*chkput) (obex_t *obex, obex_object_t *obj); + gint (*chkput) (struct OBEX_session *os); obex_rsp_t (*setpath) (struct OBEX_session *os, obex_object_t *obj); void (*disconnect) (struct OBEX_session *os); void (*reset) (struct OBEX_session *os); -- 2.47.3