This is another attempt in sending headers in correct order.
New function is ready for using it for sending headers in parts. However
I'm postponing work on suspending after sending available non-body
headers, as it is causing some problems (e.g. when the handle_async_io
would be called before OpenOBEX reaches header with suspend flag set) and
so it needs finding a better solution.
Patch 2 breaks a bit PBAP functionality - in case of requesting phone
book size, the body header will be sent as well. This is due to patch
splitting. Exact proper behaviour is back after applying patch 4.
This removes possibility of setting header type in mime driver read()
function as the functionality of adding different header types is now
supported by get_next_header().
---
plugins/filesystem.c | 13 +++----------
plugins/irmc.c | 3 +--
plugins/mas.c | 4 +---
plugins/pbap.c | 14 +++-----------
plugins/pcsuite.c | 4 +---
plugins/syncevolution.c | 6 ++----
src/mimetype.h | 2 +-
src/obex.c | 27 ++++++++-------------------
8 files changed, 20 insertions(+), 53 deletions(-)
diff --git a/plugins/filesystem.c b/plugins/filesystem.c
index b4ff556..3a8fb23 100644
--- a/plugins/filesystem.c
+++ b/plugins/filesystem.c
@@ -209,8 +209,7 @@ static int filesystem_close(void *object)
return 0;
}
-static ssize_t filesystem_read(void *object, void *buf, size_t count,
- uint8_t *hi)
+static ssize_t filesystem_read(void *object, void *buf, size_t count)
{
ssize_t ret;
@@ -218,8 +217,6 @@ static ssize_t filesystem_read(void *object, void *buf, size_t count,
if (ret < 0)
return -errno;
- *hi = OBEX_HDR_BODY;
-
return ret;
}
@@ -499,19 +496,15 @@ ssize_t string_read(void *object, void *buf, size_t count)
return len;
}
-static ssize_t folder_read(void *object, void *buf, size_t count, uint8_t *hi)
+static ssize_t folder_read(void *object, void *buf, size_t count)
{
- *hi = OBEX_HDR_BODY;
return string_read(object, buf, count);
}
-static ssize_t capability_read(void *object, void *buf, size_t count,
- uint8_t *hi)
+static ssize_t capability_read(void *object, void *buf, size_t count)
{
struct capability_object *obj = object;
- *hi = OBEX_HDR_BODY;
-
if (obj->buffer)
return string_read(obj->buffer, buf, count);
diff --git a/plugins/irmc.c b/plugins/irmc.c
index cc0b9db..0fb92be 100644
--- a/plugins/irmc.c
+++ b/plugins/irmc.c
@@ -462,7 +462,7 @@ static int irmc_close(void *object)
return 0;
}
-static ssize_t irmc_read(void *object, void *buf, size_t count, uint8_t *hi)
+static ssize_t irmc_read(void *object, void *buf, size_t count)
{
struct irmc_session *irmc = object;
int len;
@@ -471,7 +471,6 @@ static ssize_t irmc_read(void *object, void *buf, size_t count, uint8_t *hi)
if (!irmc->buffer)
return -EAGAIN;
- *hi = OBEX_HDR_BODY;
len = string_read(irmc->buffer, buf, count);
DBG("returning %d bytes", len);
return len;
diff --git a/plugins/mas.c b/plugins/mas.c
index 08e47a2..0ef8c81 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -222,12 +222,10 @@ static ssize_t any_write(void *object, const void *buf, size_t count)
return count;
}
-static ssize_t any_read(void *obj, void *buf, size_t count, uint8_t *hi)
+static ssize_t any_read(void *obj, void *buf, size_t count)
{
DBG("");
- *hi = OBEX_HDR_BODY;
-
return 0;
}
diff --git a/plugins/pbap.c b/plugins/pbap.c
index dc43867..9d4691b 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -983,8 +983,7 @@ static ssize_t vobject_pull_get_next_header(void *object, void *buf, size_t mtu,
return 0;
}
-static ssize_t vobject_pull_read(void *object, void *buf, size_t count,
- uint8_t *hi)
+static ssize_t vobject_pull_read(void *object, void *buf, size_t count)
{
struct pbap_object *obj = object;
struct pbap_session *pbap = obj->session;
@@ -999,8 +998,6 @@ static ssize_t vobject_pull_read(void *object, void *buf, size_t count,
if (pbap->params->maxlistcount == 0)
return -ENOSTR;
- *hi = OBEX_HDR_BODY;
-
len = string_read(obj->buffer, buf, count);
if (len == 0 && !obj->lastpart) {
/* in case when buffer is empty and we know that more
@@ -1035,8 +1032,7 @@ static ssize_t vobject_list_get_next_header(void *object, void *buf, size_t mtu,
return 0;
}
-static ssize_t vobject_list_read(void *object, void *buf, size_t count,
- uint8_t *hi)
+static ssize_t vobject_list_read(void *object, void *buf, size_t count)
{
struct pbap_object *obj = object;
struct pbap_session *pbap = obj->session;
@@ -1047,13 +1043,10 @@ static ssize_t vobject_list_read(void *object, void *buf, size_t count,
if (pbap->params->maxlistcount == 0)
return -ENOSTR;
- *hi = OBEX_HDR_BODY;
-
return string_read(obj->buffer, buf, count);
}
-static ssize_t vobject_vcard_read(void *object, void *buf, size_t count,
- uint8_t *hi)
+static ssize_t vobject_vcard_read(void *object, void *buf, size_t count)
{
struct pbap_object *obj = object;
@@ -1062,7 +1055,6 @@ static ssize_t vobject_vcard_read(void *object, void *buf, size_t count,
if (!obj->buffer)
return -EAGAIN;
- *hi = OBEX_HDR_BODY;
return string_read(obj->buffer, buf, count);
}
diff --git a/plugins/pcsuite.c b/plugins/pcsuite.c
index 18a3ee7..49f9286 100644
--- a/plugins/pcsuite.c
+++ b/plugins/pcsuite.c
@@ -417,13 +417,11 @@ static int backup_close(void *object)
return 0;
}
-static ssize_t backup_read(void *object, void *buf, size_t count, uint8_t *hi)
+static ssize_t backup_read(void *object, void *buf, size_t count)
{
struct backup_object *obj = object;
ssize_t ret = 0;
- *hi = OBEX_HDR_BODY;
-
if (obj->pending_call) {
DBG("cmd = %s, IN WAITING STAGE", obj->cmd);
return -EAGAIN;
diff --git a/plugins/syncevolution.c b/plugins/syncevolution.c
index 77c1bd6..7a78669 100644
--- a/plugins/syncevolution.c
+++ b/plugins/syncevolution.c
@@ -328,7 +328,7 @@ done:
return 0;
}
-static ssize_t synce_read(void *object, void *buf, size_t count, uint8_t *hi)
+static ssize_t synce_read(void *object, void *buf, size_t count)
{
struct synce_context *context = object;
DBusConnection *conn;
@@ -339,10 +339,8 @@ static ssize_t synce_read(void *object, void *buf, size_t count, uint8_t *hi)
gboolean authenticate;
DBusPendingCall *call;
- if (context->buffer) {
- *hi = OBEX_HDR_BODY;
+ if (context->buffer)
return string_read(context->buffer, buf, count);
- }
conn = obex_dbus_get_connection();
if (conn == NULL)
diff --git a/src/mimetype.h b/src/mimetype.h
index 511ab6a..1b1c234 100644
--- a/src/mimetype.h
+++ b/src/mimetype.h
@@ -35,7 +35,7 @@ struct obex_mime_type_driver {
int (*close) (void *object);
ssize_t (*get_next_header)(void *object, void *buf, size_t mtu,
uint8_t *hi);
- ssize_t (*read) (void *object, void *buf, size_t count, uint8_t *hi);
+ ssize_t (*read) (void *object, void *buf, size_t count);
ssize_t (*write) (void *object, const void *buf, size_t count);
int (*flush) (void *object);
int (*remove) (const char *name);
diff --git a/src/obex.c b/src/obex.c
index 596da6a..b8ad408 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -627,8 +627,6 @@ static int obex_write_stream(struct obex_session *os,
{
obex_headerdata_t hd;
ssize_t len;
- unsigned int flags;
- uint8_t hi;
DBG("name=%s type=%s tx_mtu=%d file=%p",
os->name ? os->name : "", os->type ? os->type : "",
@@ -640,7 +638,7 @@ static int obex_write_stream(struct obex_session *os,
if (os->object == NULL)
return -EIO;
- len = os->driver->read(os->object, os->buf, os->tx_mtu, &hi);
+ len = os->driver->read(os->object, os->buf, os->tx_mtu);
if (len < 0) {
error("read(): %s (%zd)", strerror(-len), -len);
if (len == -EAGAIN)
@@ -662,27 +660,18 @@ static int obex_write_stream(struct obex_session *os,
os->streaming = TRUE;
}
- hd.bs = os->buf;
-
- switch (hi) {
- case OBEX_HDR_BODY:
- flags = len ? OBEX_FL_STREAM_DATA : OBEX_FL_STREAM_DATAEND;
- break;
- case OBEX_HDR_APPARAM:
- flags = 0;
- break;
- default:
- error("read(): unkown header type %u", hi);
- return -EIO;
- }
-
- OBEX_ObjectAddHeader(obex, obj, hi, hd, len, flags);
-
if (len == 0) {
+ hd.bs = NULL;
+ OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY, hd, 0,
+ OBEX_FL_STREAM_DATAEND);
g_free(os->buf);
os->buf = NULL;
}
+ hd.bs = os->buf;
+ OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY, hd, len,
+ OBEX_FL_STREAM_DATA);
+
return 0;
}
--
1.7.4.1
---
plugins/pbap.c | 97 +++++++++++++++++++++++++++++++++++--------------------
1 files changed, 62 insertions(+), 35 deletions(-)
diff --git a/plugins/pbap.c b/plugins/pbap.c
index 0208731..dc43867 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -963,6 +963,26 @@ static ssize_t array_read(GByteArray *array, void *buf, size_t count)
return len;
}
+static ssize_t vobject_pull_get_next_header(void *object, void *buf, size_t mtu,
+ uint8_t *hi)
+{
+ struct pbap_object *obj = object;
+ struct pbap_session *pbap = obj->session;
+
+ if (!obj->buffer && !obj->aparams)
+ return -EAGAIN;
+
+ *hi = OBEX_HDR_APPARAM;
+
+ if (pbap->params->maxlistcount == 0 || obj->firstpacket) {
+ obj->firstpacket = FALSE;
+
+ return array_read(obj->aparams, buf, mtu);
+ }
+
+ return 0;
+}
+
static ssize_t vobject_pull_read(void *object, void *buf, size_t count,
uint8_t *hi)
{
@@ -976,33 +996,43 @@ static ssize_t vobject_pull_read(void *object, void *buf, size_t count,
if (!obj->buffer && !obj->aparams)
return -EAGAIN;
- if (pbap->params->maxlistcount == 0) {
- /* PhoneBookSize */
- *hi = obj->aparams->len ? OBEX_HDR_APPARAM : OBEX_HDR_BODY;
- return array_read(obj->aparams, buf, count);
- } else if (obj->firstpacket) {
- /* NewMissedCalls */
- *hi = obj->aparams->len ? OBEX_HDR_APPARAM : OBEX_HDR_BODY;
- obj->firstpacket = FALSE;
- return array_read(obj->aparams, buf, count);
- } else {
- /* Stream data */
- *hi = OBEX_HDR_BODY;
- len = string_read(obj->buffer, buf, count);
- if (len == 0 && !obj->lastpart) {
- /* in case when buffer is empty and we know that more
- * data is still available in backend, requesting new
- * data part via phonebook_pull_read and returning
- * -EAGAIN to suspend request for now */
- ret = phonebook_pull_read(obj->request);
- if (ret)
- return -EPERM;
-
- return -EAGAIN;
- }
+ if (pbap->params->maxlistcount == 0)
+ return -ENOSTR;
+
+ *hi = OBEX_HDR_BODY;
- return len;
+ len = string_read(obj->buffer, buf, count);
+ if (len == 0 && !obj->lastpart) {
+ /* in case when buffer is empty and we know that more
+ * data is still available in backend, requesting new
+ * data part via phonebook_pull_read and returning
+ * -EAGAIN to suspend request for now */
+ ret = phonebook_pull_read(obj->request);
+ if (ret)
+ return -EPERM;
+
+ return -EAGAIN;
}
+
+ return len;
+}
+
+static ssize_t vobject_list_get_next_header(void *object, void *buf, size_t mtu,
+ uint8_t *hi)
+{
+ struct pbap_object *obj = object;
+ struct pbap_session *pbap = obj->session;
+
+ /* Backend still busy reading contacts */
+ if (!pbap->cache.valid)
+ return -EAGAIN;
+
+ *hi = OBEX_HDR_APPARAM;
+
+ if (pbap->params->maxlistcount == 0)
+ return array_read(obj->aparams, buf, mtu);
+
+ return 0;
}
static ssize_t vobject_list_read(void *object, void *buf, size_t count,
@@ -1014,17 +1044,12 @@ static ssize_t vobject_list_read(void *object, void *buf, size_t count,
DBG("valid %d maxlistcount %d", pbap->cache.valid,
pbap->params->maxlistcount);
- /* Backend still busy reading contacts */
- if (!pbap->cache.valid)
- return -EAGAIN;
+ if (pbap->params->maxlistcount == 0)
+ return -ENOSTR;
- if (pbap->params->maxlistcount == 0) {
- *hi = obj->aparams->len ? OBEX_HDR_APPARAM : OBEX_HDR_BODY;
- return array_read(obj->aparams, buf, count);
- } else {
- *hi = OBEX_HDR_BODY;
- return string_read(obj->buffer, buf, count);
- }
+ *hi = OBEX_HDR_BODY;
+
+ return string_read(obj->buffer, buf, count);
}
static ssize_t vobject_vcard_read(void *object, void *buf, size_t count,
@@ -1048,6 +1073,7 @@ static struct obex_mime_type_driver mime_pull = {
.open = vobject_pull_open,
.close = vobject_close,
.read = vobject_pull_read,
+ .get_next_header = vobject_pull_get_next_header,
};
static struct obex_mime_type_driver mime_list = {
@@ -1057,6 +1083,7 @@ static struct obex_mime_type_driver mime_list = {
.open = vobject_list_open,
.close = vobject_close,
.read = vobject_list_read,
+ .get_next_header = vobject_list_get_next_header,
};
static struct obex_mime_type_driver mime_vcard = {
--
1.7.4.1
This adds the function for mime drivers that allows adding OBEX headers
before body streaming is started.
---
src/mimetype.h | 2 +
src/obex-priv.h | 1 +
src/obex.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++---
3 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/src/mimetype.h b/src/mimetype.h
index 8472684..511ab6a 100644
--- a/src/mimetype.h
+++ b/src/mimetype.h
@@ -33,6 +33,8 @@ struct obex_mime_type_driver {
void *(*open) (const char *name, int oflag, mode_t mode,
void *driver_data, size_t *size, int *err);
int (*close) (void *object);
+ ssize_t (*get_next_header)(void *object, void *buf, size_t mtu,
+ uint8_t *hi);
ssize_t (*read) (void *object, void *buf, size_t count, uint8_t *hi);
ssize_t (*write) (void *object, const void *buf, size_t count);
int (*flush) (void *object);
diff --git a/src/obex-priv.h b/src/obex-priv.h
index 8c722dc..51a7739 100644
--- a/src/obex-priv.h
+++ b/src/obex-priv.h
@@ -46,6 +46,7 @@ struct obex_session {
obex_object_t *obj;
struct obex_mime_type_driver *driver;
gboolean streaming;
+ gboolean headers_sent;
};
int obex_session_start(GIOChannel *io, uint16_t tx_mtu, uint16_t rx_mtu,
diff --git a/src/obex.c b/src/obex.c
index 3ab81d4..596da6a 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -310,6 +310,7 @@ static void os_reset_session(struct obex_session *os)
os->pending = 0;
os->offset = 0;
os->size = OBJECT_SIZE_DELETE;
+ os->headers_sent = FALSE;
os->streaming = FALSE;
}
@@ -685,6 +686,53 @@ static int obex_write_stream(struct obex_session *os,
return 0;
}
+static int obex_write(struct obex_session *os, obex_t *obex, obex_object_t *obj)
+{
+ obex_headerdata_t hd;
+ ssize_t len;
+ uint8_t hi;
+
+ DBG("name=%s type=%s tx_mtu=%d file=%p",
+ os->name ? os->name : "", os->type ? os->type : "",
+ os->tx_mtu, os->object);
+
+ if (os->aborted)
+ return -EPERM;
+
+ if (os->object == NULL)
+ return -EIO;
+
+ if (os->headers_sent)
+ return obex_write_stream(os, obex, obj);
+
+ if (!os->driver->get_next_header)
+ goto skip;
+
+ while ((len = os->driver->get_next_header(os->object, os->buf,
+ os->tx_mtu, &hi)) != 0) {
+ if (len < 0) {
+ error("get_next_header(): %s (%zd)", strerror(-len),
+ -len);
+
+ if (len == -EAGAIN)
+ return len;
+
+ g_free(os->buf);
+ os->buf = NULL;
+
+ return len;
+ }
+
+ hd.bs = os->buf;
+ OBEX_ObjectAddHeader(obex, obj, hi, hd, len, 0);
+ }
+
+skip:
+ os->headers_sent = TRUE;
+
+ return obex_write_stream(os, obex, obj);
+}
+
static gboolean handle_async_io(void *object, int flags, int err,
void *user_data)
{
@@ -697,16 +745,19 @@ static gboolean handle_async_io(void *object, int flags, int err,
}
if (flags & (G_IO_IN | G_IO_PRI))
- ret = obex_write_stream(os, os->obex, os->obj);
+ ret = obex_write(os, os->obex, os->obj);
else if ((flags & G_IO_OUT) && os->pending > 0)
ret = obex_read_stream(os, os->obex, os->obj);
proceed:
- if (ret < 0) {
+ if (ret == -EAGAIN) {
+ return TRUE;
+ } else if (ret < 0) {
os_set_response(os->obj, ret);
OBEX_CancelRequest(os->obex, TRUE);
- } else
+ } else {
OBEX_ResumeRequest(os->obex);
+ }
return FALSE;
}
@@ -729,6 +780,7 @@ static void cmd_get(struct obex_session *os, obex_t *obex, obex_object_t *obj)
g_return_if_fail(chk_cid(obex, obj, os->cid));
+ os->headers_sent = FALSE;
os->streaming = FALSE;
while (OBEX_ObjectGetNextHeader(obex, obj, &hi, &hd, &hlen)) {
@@ -813,7 +865,7 @@ static void cmd_get(struct obex_session *os, obex_t *obex, obex_object_t *obj)
/* Try to write to stream and suspend the stream immediately
* if no data available to send. */
- err = obex_write_stream(os, obex, obj);
+ err = obex_write(os, obex, obj);
if (err == -EAGAIN) {
OBEX_SuspendRequest(obex, obj);
os->obj = obj;
--
1.7.4.1
This removes stream argument from service driver get() function. Now the
streaming is started automatically when first portion of data is
received.
Additionally the possibility to not send body header at all is added. This
can be achieved by returning -ENOSTR from mime plugin read() function.
---
plugins/ftp.c | 6 +-----
plugins/ftp.h | 3 +--
plugins/irmc.c | 3 +--
plugins/mas.c | 5 +----
plugins/opp.c | 6 +-----
plugins/pbap.c | 11 ++++-------
plugins/pcsuite.c | 4 ++--
plugins/syncevolution.c | 5 +----
src/obex-priv.h | 1 +
src/obex.c | 24 +++++++++++++++---------
src/service.h | 2 +-
11 files changed, 29 insertions(+), 41 deletions(-)
diff --git a/plugins/ftp.c b/plugins/ftp.c
index 79223bf..4962326 100644
--- a/plugins/ftp.c
+++ b/plugins/ftp.c
@@ -213,8 +213,7 @@ void *ftp_connect(struct obex_session *os, int *err)
return ftp;
}
-int ftp_get(struct obex_session *os, obex_object_t *obj, gboolean *stream,
- void *user_data)
+int ftp_get(struct obex_session *os, obex_object_t *obj, void *user_data)
{
struct ftp_session *ftp = user_data;
const char *type = obex_get_type(os);
@@ -229,9 +228,6 @@ int ftp_get(struct obex_session *os, obex_object_t *obj, gboolean *stream,
if (ret < 0)
return ret;
- if (stream)
- *stream = TRUE;
-
return 0;
}
diff --git a/plugins/ftp.h b/plugins/ftp.h
index 2374125..d929cde 100644
--- a/plugins/ftp.h
+++ b/plugins/ftp.h
@@ -22,8 +22,7 @@
*/
void *ftp_connect(struct obex_session *os, int *err);
-int ftp_get(struct obex_session *os, obex_object_t *obj, gboolean *stream,
- void *user_data);
+int ftp_get(struct obex_session *os, obex_object_t *obj, void *user_data);
int ftp_chkput(struct obex_session *os, void *user_data);
int ftp_put(struct obex_session *os, obex_object_t *obj, void *user_data);
int ftp_setpath(struct obex_session *os, obex_object_t *obj, void *user_data);
diff --git a/plugins/irmc.c b/plugins/irmc.c
index cd7f386..cc0b9db 100644
--- a/plugins/irmc.c
+++ b/plugins/irmc.c
@@ -233,7 +233,7 @@ static void *irmc_connect(struct obex_session *os, int *err)
}
static int irmc_get(struct obex_session *os, obex_object_t *obj,
- gboolean *stream, void *user_data)
+ void *user_data)
{
struct irmc_session *irmc = user_data;
const char *type = obex_get_type(os);
@@ -244,7 +244,6 @@ static int irmc_get(struct obex_session *os, obex_object_t *obj,
DBG("name %s type %s irmc %p", name, type ? type : "NA", irmc);
path = g_strdup(name);
- *stream = TRUE;
ret = obex_get_stream_start(os, path);
diff --git a/plugins/mas.c b/plugins/mas.c
index d13625c..08e47a2 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -134,8 +134,7 @@ static void mas_disconnect(struct obex_session *os, void *user_data)
mas_clean(mas);
}
-static int mas_get(struct obex_session *os, obex_object_t *obj,
- gboolean *stream, void *user_data)
+static int mas_get(struct obex_session *os, obex_object_t *obj, void *user_data)
{
struct mas_session *mas = user_data;
const char *type = obex_get_type(os);
@@ -148,8 +147,6 @@ static int mas_get(struct obex_session *os, obex_object_t *obj,
if (type == NULL)
return -EBADR;
- *stream = FALSE;
-
ret = obex_get_stream_start(os, name);
if (ret < 0)
goto failed;
diff --git a/plugins/opp.c b/plugins/opp.c
index 17c4356..4f0ed08 100644
--- a/plugins/opp.c
+++ b/plugins/opp.c
@@ -170,8 +170,7 @@ static int opp_put(struct obex_session *os, obex_object_t *obj,
return 0;
}
-static int opp_get(struct obex_session *os, obex_object_t *obj,
- gboolean *stream, void *user_data)
+static int opp_get(struct obex_session *os, obex_object_t *obj, void *user_data)
{
const char *type;
@@ -190,9 +189,6 @@ static int opp_get(struct obex_session *os, obex_object_t *obj,
} else
return -EPERM;
- if (stream)
- *stream = TRUE;
-
return 0;
}
diff --git a/plugins/pbap.c b/plugins/pbap.c
index 0356ae7..0208731 100644
--- a/plugins/pbap.c
+++ b/plugins/pbap.c
@@ -625,7 +625,7 @@ static void *pbap_connect(struct obex_session *os, int *err)
}
static int pbap_get(struct obex_session *os, obex_object_t *obj,
- gboolean *stream, void *user_data)
+ void *user_data)
{
struct pbap_session *pbap = user_data;
const char *type = obex_get_type(os);
@@ -663,7 +663,6 @@ static int pbap_get(struct obex_session *os, obex_object_t *obj,
else
path = g_build_filename("/", name, NULL);
- *stream = (params->maxlistcount == 0 ? FALSE : TRUE);
} else if (strcmp(type, VCARDLISTING_TYPE) == 0) {
/* Always relative */
if (!name || strlen(name) == 0)
@@ -673,11 +672,9 @@ static int pbap_get(struct obex_session *os, obex_object_t *obj,
/* Current folder + relative path */
path = g_build_filename(pbap->folder, name, NULL);
- *stream = (params->maxlistcount == 0 ? FALSE : TRUE);
} else if (strcmp(type, VCARDENTRY_TYPE) == 0) {
/* File name only */
path = g_strdup(name);
- *stream = TRUE;
} else
return -EBADR;
@@ -981,11 +978,11 @@ static ssize_t vobject_pull_read(void *object, void *buf, size_t count,
if (pbap->params->maxlistcount == 0) {
/* PhoneBookSize */
- *hi = OBEX_HDR_APPARAM;
+ *hi = obj->aparams->len ? OBEX_HDR_APPARAM : OBEX_HDR_BODY;
return array_read(obj->aparams, buf, count);
} else if (obj->firstpacket) {
/* NewMissedCalls */
- *hi = OBEX_HDR_APPARAM;
+ *hi = obj->aparams->len ? OBEX_HDR_APPARAM : OBEX_HDR_BODY;
obj->firstpacket = FALSE;
return array_read(obj->aparams, buf, count);
} else {
@@ -1022,7 +1019,7 @@ static ssize_t vobject_list_read(void *object, void *buf, size_t count,
return -EAGAIN;
if (pbap->params->maxlistcount == 0) {
- *hi = OBEX_HDR_APPARAM;
+ *hi = obj->aparams->len ? OBEX_HDR_APPARAM : OBEX_HDR_BODY;
return array_read(obj->aparams, buf, count);
} else {
*hi = OBEX_HDR_BODY;
diff --git a/plugins/pcsuite.c b/plugins/pcsuite.c
index 5545917..18a3ee7 100644
--- a/plugins/pcsuite.c
+++ b/plugins/pcsuite.c
@@ -181,13 +181,13 @@ fail:
}
static int pcsuite_get(struct obex_session *os, obex_object_t *obj,
- gboolean *stream, void *user_data)
+ void *user_data)
{
struct pcsuite_session *pcsuite = user_data;
DBG("%p", pcsuite);
- return ftp_get(os, obj, stream, pcsuite->ftp);
+ return ftp_get(os, obj, pcsuite->ftp);
}
static int pcsuite_chkput(struct obex_session *os, void *user_data)
diff --git a/plugins/syncevolution.c b/plugins/syncevolution.c
index ea3eb7a..77c1bd6 100644
--- a/plugins/syncevolution.c
+++ b/plugins/syncevolution.c
@@ -250,11 +250,8 @@ static int synce_put(struct obex_session *os, obex_object_t *obj,
}
static int synce_get(struct obex_session *os, obex_object_t *obj,
- gboolean *stream, void *user_data)
+ void *user_data)
{
- if (stream)
- *stream = TRUE;
-
return obex_get_stream_start(os, NULL);
}
diff --git a/src/obex-priv.h b/src/obex-priv.h
index 0caa0dd..8c722dc 100644
--- a/src/obex-priv.h
+++ b/src/obex-priv.h
@@ -45,6 +45,7 @@ struct obex_session {
obex_t *obex;
obex_object_t *obj;
struct obex_mime_type_driver *driver;
+ gboolean streaming;
};
int obex_session_start(GIOChannel *io, uint16_t tx_mtu, uint16_t rx_mtu,
diff --git a/src/obex.c b/src/obex.c
index 064fe4b..3ab81d4 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -310,6 +310,7 @@ static void os_reset_session(struct obex_session *os)
os->pending = 0;
os->offset = 0;
os->size = OBJECT_SIZE_DELETE;
+ os->streaming = FALSE;
}
static void obex_session_free(struct obex_session *os)
@@ -643,14 +644,23 @@ static int obex_write_stream(struct obex_session *os,
error("read(): %s (%zd)", strerror(-len), -len);
if (len == -EAGAIN)
return len;
- else if (len == -ENOSTR)
- return 0;
g_free(os->buf);
os->buf = NULL;
+
+ if (len == -ENOSTR)
+ return 0;
+
return len;
}
+ if (!os->streaming) {
+ hd.bs = NULL;
+ OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY, hd, 0,
+ OBEX_FL_STREAM_START);
+ os->streaming = TRUE;
+ }
+
hd.bs = os->buf;
switch (hi) {
@@ -704,7 +714,6 @@ proceed:
static void cmd_get(struct obex_session *os, obex_t *obex, obex_object_t *obj)
{
obex_headerdata_t hd;
- gboolean stream;
unsigned int hlen;
uint8_t hi;
int err;
@@ -720,6 +729,8 @@ static void cmd_get(struct obex_session *os, obex_t *obex, obex_object_t *obj)
g_return_if_fail(chk_cid(obex, obj, os->cid));
+ os->streaming = FALSE;
+
while (OBEX_ObjectGetNextHeader(obex, obj, &hi, &hd, &hlen)) {
switch (hi) {
case OBEX_HDR_NAME:
@@ -781,7 +792,7 @@ static void cmd_get(struct obex_session *os, obex_t *obex, obex_object_t *obj)
return;
}
- err = os->service->get(os, obj, &stream, os->service_data);
+ err = os->service->get(os, obj, os->service_data);
if (err < 0)
goto done;
@@ -800,11 +811,6 @@ static void cmd_get(struct obex_session *os, obex_t *obex, obex_object_t *obj)
goto done;
}
- if (stream)
- /* Standard data stream */
- OBEX_ObjectAddHeader(obex, obj, OBEX_HDR_BODY, hd, 0,
- OBEX_FL_STREAM_START);
-
/* Try to write to stream and suspend the stream immediately
* if no data available to send. */
err = obex_write_stream(os, obex, obj);
diff --git a/src/service.h b/src/service.h
index a844885..4d9d683 100644
--- a/src/service.h
+++ b/src/service.h
@@ -33,7 +33,7 @@ struct obex_service_driver {
void *(*connect) (struct obex_session *os, int *err);
void (*progress) (struct obex_session *os, void *user_data);
int (*get) (struct obex_session *os, obex_object_t *obj,
- gboolean *stream, void *user_data);
+ void *user_data);
int (*put) (struct obex_session *os, obex_object_t *obj,
void *user_data);
int (*chkput) (struct obex_session *os, void *user_data);
--
1.7.4.1
---
src/obex.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/src/obex.c b/src/obex.c
index e6585ca..064fe4b 100644
--- a/src/obex.c
+++ b/src/obex.c
@@ -693,7 +693,7 @@ static gboolean handle_async_io(void *object, int flags, int err,
proceed:
if (ret < 0) {
- os_set_response(os->obj, err);
+ os_set_response(os->obj, ret);
OBEX_CancelRequest(os->obex, TRUE);
} else
OBEX_ResumeRequest(os->obex);
--
1.7.4.1
Hi Slawek,
On Mon, Jun 27, 2011, Slawomir Bochenski wrote:
> This removes possibility of setting header type in mime driver read()
> function as the functionality of adding different header types is now
> supported by get_next_header().
> ---
> plugins/filesystem.c | 13 +++----------
> plugins/irmc.c | 3 +--
> plugins/mas.c | 4 +---
> plugins/pbap.c | 14 +++-----------
> plugins/pcsuite.c | 4 +---
> plugins/syncevolution.c | 6 ++----
> src/mimetype.h | 2 +-
> src/obex.c | 27 ++++++++-------------------
> 8 files changed, 20 insertions(+), 53 deletions(-)
I've applied the other four patches but this one doesn't apply cleanly.
I suspect this is due to some other cleanup patches that have gone in
lately.
Johan