diff --git a/obexd/src/ftp.c b/obexd/src/ftp.c
index 5c442fc..b0c13a4 100644
--- a/obexd/src/ftp.c
+++ b/obexd/src/ftp.c
return ret;
}
-static gboolean folder_listing(struct obex_session *os, guint32 *size)
+static gint folder_listing(struct obex_session *os, guint32 *size)
{
struct stat fstat, dstat;
struct dirent *ep;
DIR *dp;
GString *listing;
gboolean root;
- int err;
+ gint err;
listing = g_string_new(FL_VERSION);
listing = g_string_append(listing, FL_TYPE);
}
if (err < 0) {
+ err = -errno;
error("%s: %s(%d)", root ? "stat" : "lstat",
strerror(errno), errno);
goto failed;
dp = opendir(os->current_folder);
if (dp == NULL) {
+ err = -errno;
error("opendir: failed to access %s", os->current_folder);
goto failed;
}
*size = listing->len + 1;
os->buf = (guint8*) g_string_free(listing, FALSE);
- return TRUE;
+ return 0;
failed:
g_string_free(listing, TRUE);
- return FALSE;
+ return err;
}
-static gboolean get_capability(struct obex_session *os, guint32 *size)
+static gint get_capability(struct obex_session *os, guint32 *size)
{
GError *gerr = NULL;
gchar *buf;
gboolean ret;
if (os->server->capability == NULL)
- return FALSE;
+ return -ENOENT;
if (os->server->capability[0] != '!')
return os_prepare_get(os, os->server->capability, size);
if (ret == FALSE) {
error("g_spawn_command_line_sync: %s", gerr->message);
g_error_free(gerr);
- return FALSE;
+ return -EPERM;
}
if (WEXITSTATUS(exit) != EXIT_SUCCESS) {
g_free(buf);
- return FALSE;
+ return -EPERM;
}
os->buf = (guint8 *) buf;
*size = strlen(buf);
- return TRUE;
+ return 0;
}
-static gboolean get_by_type(struct obex_session *os, gchar *type, guint32 *size)
+static gint get_by_type(struct obex_session *os, gchar *type, guint32 *size)
{
if (type == NULL)
- return FALSE;
+ return -ENOENT;
if (g_str_equal(type, CAP_TYPE))
return get_capability(os, size);
return FALSE;
}
-static gboolean ftp_prepare_get(struct obex_session *os, gchar *file,
+static gint ftp_prepare_get(struct obex_session *os, gchar *file,
guint32 *size)
{
gboolean root;
if (!root || !os->server->symlinks) {
struct stat dstat;
- int err;
+ gint err;
- err = lstat(file, &dstat);
- if (err < 0) {
+ if (lstat(file, &dstat) < 0) {
+ err = -errno;
debug("lstat: %s(%d)", strerror(errno), errno);
- return FALSE;
+ return err;
}
if (S_ISLNK(dstat.st_mode))
- return FALSE;
+ return -EPERM;
}
return os_prepare_get(os, file, size);
obex_headerdata_t hv;
struct obex_session *os;
guint32 size;
- gboolean ret;
+ gint err;
gchar *path;
os = OBEX_GetUserData(obex);
if (os->current_folder == NULL)
goto fail;
- if (!get_by_type(os, os->type, &size)) {
+ err = get_by_type(os, os->type, &size);
+ if (err < 0) {
if (!os->name)
goto fail;
path = g_build_filename(os->current_folder, os->name, NULL);
- ret = ftp_prepare_get(os, path, &size);
+ err = ftp_prepare_get(os, path, &size);
g_free(path);
- if (!ret)
+ if (err < 0)
goto fail;
}
return;
fail:
- OBEX_ObjectSetRsp(obj, OBEX_RSP_FORBIDDEN, OBEX_RSP_FORBIDDEN);
+ switch (err) {
+ case -ENOENT:
+ OBEX_ObjectSetRsp(obj, OBEX_RSP_NOT_FOUND, OBEX_RSP_NOT_FOUND);
+ break;
+ default:
+ OBEX_ObjectSetRsp(obj, OBEX_RSP_FORBIDDEN, OBEX_RSP_FORBIDDEN);
+ }
}
static gint ftp_delete(struct obex_session *os)
diff --git a/obexd/src/obex.c b/obexd/src/obex.c
index 6badc47..3172c81 100644
--- a/obexd/src/obex.c
+++ b/obexd/src/obex.c
os->cmds->setpath(obex, obj);
}
-gboolean os_prepare_get(struct obex_session *os, gchar *file, guint32 *size)
+int os_prepare_get(struct obex_session *os, gchar *file, guint32 *size)
{
- gint fd;
+ gint fd, err;
struct stat stats;
fd = open(file, O_RDONLY);
*size = stats.st_size;
- return TRUE;
+ return 0;
fail:
+ err = -errno;
if (fd >= 0)
close(fd);
- return FALSE;
+ return err;
}
static gint obex_write_stream(struct obex_session *os,
diff --git a/obexd/src/obex.h b/obexd/src/obex.h
index b13219d..aab863a 100644
--- a/obexd/src/obex.h
+++ b/obexd/src/obex.h
void pbap_phonebook_context_destroy(struct obex_session *session);
struct obex_session *pbap_get_session(struct phonebook_context *context);
-gboolean os_prepare_get(struct obex_session *os, gchar *file, guint32 *size);
+gint os_prepare_get(struct obex_session *os, gchar *file, guint32 *size);
gint os_prepare_put(struct obex_session *os);
void server_free(struct server *server);
diff --git a/obexd/src/opp.c b/obexd/src/opp.c
index 42c23d9..9a50d68 100644
--- a/obexd/src/opp.c
+++ b/obexd/src/opp.c
goto fail;
if (g_str_equal(os->type, VCARD_TYPE)) {
- if (!os_prepare_get(os, VCARD_FILE, &size))
+ if (os_prepare_get(os, VCARD_FILE, &size) < 0)
goto fail;
} else
goto fail;