2011-09-02 08:57:40

by Slawomir Bochenski

[permalink] [raw]
Subject: [PATCH obexd 1/5] MAP: Add typedef for folder listing callback

---
plugins/messages-dummy.c | 3 +--
plugins/messages.h | 6 ++++--
2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/plugins/messages-dummy.c b/plugins/messages-dummy.c
index 295eb61..408651e 100644
--- a/plugins/messages-dummy.c
+++ b/plugins/messages-dummy.c
@@ -145,8 +145,7 @@ int messages_set_folder(void *s, const char *name, gboolean cdup)
int messages_get_folder_listing(void *session,
const char *name,
uint16_t max, uint16_t offset,
- void (*callback)(void *session, int err, uint16_t size,
- const char *name, void *user_data),
+ messages_folder_listing_cb callback,
void *user_data)
{
return -EINVAL;
diff --git a/plugins/messages.h b/plugins/messages.h
index c862b07..d9348c7 100644
--- a/plugins/messages.h
+++ b/plugins/messages.h
@@ -202,11 +202,13 @@ int messages_set_folder(void *session, const char *name, gboolean cdup);
* Callback shall be called for every entry of the listing. 'name' is the
* subdirectory name.
*/
+typedef void (*messages_folder_listing_cb)(void *session, int err,
+ uint16_t size, const char *name, void *user_data);
+
int messages_get_folder_listing(void *session,
const char *name,
uint16_t max, uint16_t offset,
- void (*callback)(void *session, int err, uint16_t size,
- const char *name, void *user_data),
+ messages_folder_listing_cb callback,
void *user_data);

/* Retrieves messages listing from a current directory.
--
1.7.4.1



2011-09-27 09:39:55

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH obexd 1/5] MAP: Add typedef for folder listing callback

Hi Slawek,

On Fri, Sep 02, 2011, Slawomir Bochenski wrote:
> ---
> plugins/messages-dummy.c | 3 +--
> plugins/messages.h | 6 ++++--
> 2 files changed, 5 insertions(+), 4 deletions(-)

All five patches applied. Thanks.

Johan

2011-09-02 08:57:44

by Slawomir Bochenski

[permalink] [raw]
Subject: [PATCH obexd 5/5] MAP: Use pointers to const where appropriate

---
plugins/messages-dummy.c | 5 +++--
plugins/messages-tracker.c | 26 +++++++++++---------------
plugins/messages.h | 5 +++--
3 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/plugins/messages-dummy.c b/plugins/messages-dummy.c
index 9295864..e96b13b 100644
--- a/plugins/messages-dummy.c
+++ b/plugins/messages-dummy.c
@@ -90,7 +90,7 @@ void messages_disconnect(void *s)

int messages_set_notification_registration(void *session,
void (*send_event)(void *session,
- struct messages_event *event, void *user_data),
+ const struct messages_event *event, void *user_data),
void *user_data)
{
return -EINVAL;
@@ -153,7 +153,8 @@ int messages_get_folder_listing(void *session,

int messages_get_messages_listing(void *session,
const char *name,
- uint16_t max, uint16_t offset, struct messages_filter *filter,
+ uint16_t max, uint16_t offset,
+ const struct messages_filter *filter,
messages_get_messages_listing_cb callback,
void *user_data)
{
diff --git a/plugins/messages-tracker.c b/plugins/messages-tracker.c
index 22d923d..43321f6 100644
--- a/plugins/messages-tracker.c
+++ b/plugins/messages-tracker.c
@@ -182,7 +182,7 @@ void messages_disconnect(void *s)

int messages_set_notification_registration(void *session,
void (*send_event)(void *session,
- struct messages_event *event, void *user_data),
+ const struct messages_event *event, void *user_data),
void *user_data)
{
return -EINVAL;
@@ -280,12 +280,10 @@ static gboolean async_get_folder_listing(void *s) {
return FALSE;
}

-int messages_get_folder_listing(void *s,
- const char *name,
- uint16_t max, uint16_t offset,
- void (*callback)(void *session, int err, uint16_t size,
- const char *name, void *user_data),
- void *user_data)
+int messages_get_folder_listing(void *s, const char *name,
+ uint16_t max, uint16_t offset,
+ messages_folder_listing_cb callback,
+ void *user_data)
{
struct session *session = s;
session->name = name;
@@ -301,12 +299,11 @@ int messages_get_folder_listing(void *s,
}

int messages_get_messages_listing(void *session,
- const char *name,
- uint16_t max, uint16_t offset, struct messages_filter *filter,
- void (*callback)(void *session, int err, uint16_t size,
- gboolean newmsg, const struct messages_message *message,
- void *user_data),
- void *user_data)
+ const char *name,
+ uint16_t max, uint16_t offset,
+ const struct messages_filter *filter,
+ messages_get_messages_listing_cb callback,
+ void *user_data)
{
return -EINVAL;
}
@@ -314,8 +311,7 @@ int messages_get_messages_listing(void *session,
int messages_get_message(void *session,
const char *handle,
unsigned long flags,
- void (*callback)(void *session, int err, gboolean fmore,
- const char *chunk, void *user_data),
+ messages_get_message_cb callback,
void *user_data)
{
return -EINVAL;
diff --git a/plugins/messages.h b/plugins/messages.h
index 9e0b091..6982edd 100644
--- a/plugins/messages.h
+++ b/plugins/messages.h
@@ -179,7 +179,7 @@ void messages_disconnect(void *session);
*/
int messages_set_notification_registration(void *session,
void (*send_event)(void *session,
- struct messages_event *event, void *user_data),
+ const struct messages_event *event, void *user_data),
void *user_data);

/* Changes current directory.
@@ -230,7 +230,8 @@ typedef void (*messages_get_messages_listing_cb)(void *session, int err,

int messages_get_messages_listing(void *session,
const char *name,
- uint16_t max, uint16_t offset, struct messages_filter *filter,
+ uint16_t max, uint16_t offset,
+ const struct messages_filter *filter,
messages_get_messages_listing_cb callback,
void *user_data);

--
1.7.4.1


2011-09-02 08:57:43

by Slawomir Bochenski

[permalink] [raw]
Subject: [PATCH obexd 4/5] MAP: Add basic support for message retrieval

---
plugins/mas.c | 51 +++++++++++++++++++++++++++++++++++++++++++++-
plugins/messages-dummy.c | 3 +-
plugins/messages.h | 6 +++-
3 files changed, 55 insertions(+), 5 deletions(-)

diff --git a/plugins/mas.c b/plugins/mas.c
index e67f661..46ff2e7 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -342,6 +342,30 @@ proceed:
obex_object_set_io_flags(mas, G_IO_IN, 0);
}

+static void get_message_cb(void *session, int err, gboolean fmore,
+ const char *chunk, void *user_data)
+{
+ struct mas_session *mas = user_data;
+
+ DBG("");
+
+ if (err < 0 && err != -EAGAIN) {
+ obex_object_set_io_flags(mas, G_IO_ERR, err);
+ return;
+ }
+
+ if (!chunk) {
+ mas->finished = TRUE;
+ goto proceed;
+ }
+
+ g_string_append(mas->buffer, chunk);
+
+proceed:
+ if (err != -EAGAIN)
+ obex_object_set_io_flags(mas, G_IO_IN, 0);
+}
+
static void get_folder_listing_cb(void *session, int err, uint16_t size,
const char *name, void *user_data)
{
@@ -454,6 +478,31 @@ static void *msg_listing_open(const char *name, int oflag, mode_t mode,
return mas;
}

+static void *message_open(const char *name, int oflag, mode_t mode,
+ void *driver_data, size_t *size, int *err)
+{
+ struct mas_session *mas = driver_data;
+
+ DBG("");
+
+ if (oflag != O_RDONLY) {
+ DBG("Message pushing unsupported");
+ *err = -EINVAL;
+
+ return NULL;
+ }
+
+ *err = messages_get_message(mas->backend_data, name, 0,
+ get_message_cb, mas);
+
+ mas->buffer = g_string_new("");
+
+ if (*err < 0)
+ return NULL;
+ else
+ return mas;
+}
+
static void *any_open(const char *name, int oflag, mode_t mode,
void *driver_data, size_t *size, int *err)
{
@@ -528,7 +577,7 @@ static struct obex_mime_type_driver mime_message = {
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.mimetype = "x-bt/message",
- .open = any_open,
+ .open = message_open,
.close = any_close,
.read = any_read,
.write = any_write,
diff --git a/plugins/messages-dummy.c b/plugins/messages-dummy.c
index b0b74d7..9295864 100644
--- a/plugins/messages-dummy.c
+++ b/plugins/messages-dummy.c
@@ -163,8 +163,7 @@ int messages_get_messages_listing(void *session,
int messages_get_message(void *session,
const char *handle,
unsigned long flags,
- void (*callback)(void *session, int err, gboolean fmore,
- const char *chunk, void *user_data),
+ messages_get_message_cb callback,
void *user_data)
{
return -EINVAL;
diff --git a/plugins/messages.h b/plugins/messages.h
index f931eb4..9e0b091 100644
--- a/plugins/messages.h
+++ b/plugins/messages.h
@@ -258,11 +258,13 @@ int messages_get_messages_listing(void *session,
*
* Callback allows for returning bMessage in chunks.
*/
+typedef void (*messages_get_message_cb)(void *session, int err, gboolean fmore,
+ const char *chunk, void *user_data);
+
int messages_get_message(void *session,
const char *handle,
unsigned long flags,
- void (*callback)(void *session, int err, gboolean fmore,
- const char *chunk, void *user_data),
+ messages_get_message_cb callback,
void *user_data);

/* Aborts currently pending request.
--
1.7.4.1


2011-09-02 08:57:42

by Slawomir Bochenski

[permalink] [raw]
Subject: [PATCH obexd 3/5] MAP: Add basic messages listing retrieval support

---
plugins/mas.c | 145 +++++++++++++++++++++++++++++++++++++++++++++-
plugins/messages-dummy.c | 4 +-
plugins/messages.h | 9 ++-
3 files changed, 151 insertions(+), 7 deletions(-)

diff --git a/plugins/mas.c b/plugins/mas.c
index 8c25d84..e67f661 100644
--- a/plugins/mas.c
+++ b/plugins/mas.c
@@ -98,6 +98,9 @@
#define FL_FOLDER_ELEMENT "<folder name=\"%s\"/>"
#define FL_BODY_END "</folder-listing>"

+#define ML_BODY_BEGIN "<MAP-msg-listing version=\"1.0\">"
+#define ML_BODY_END "</MAP-msg-listing>"
+
struct mas_session {
struct mas_request *request;
void *backend_data;
@@ -224,6 +227,121 @@ static void g_string_append_escaped_printf(GString *string, const gchar *format,
va_end(ap);
}

+static const char *yesorno(gboolean a)
+{
+ if (a)
+ return "yes";
+
+ return "no";
+}
+
+static void get_messages_listing_cb(void *session, int err,
+ uint16_t size, gboolean newmsg,
+ const struct messages_message *entry,
+ void *user_data)
+{
+ struct mas_session *mas = user_data;
+
+ if (err < 0 && err != -EAGAIN) {
+ obex_object_set_io_flags(mas, G_IO_ERR, err);
+ return;
+ }
+
+ if (!mas->nth_call) {
+ g_string_append(mas->buffer, ML_BODY_BEGIN);
+ mas->nth_call = TRUE;
+ }
+
+ if (!entry) {
+ g_string_append(mas->buffer, ML_BODY_END);
+ mas->finished = TRUE;
+
+ goto proceed;
+ }
+
+ g_string_append(mas->buffer, "<msg");
+
+ g_string_append_escaped_printf(mas->buffer, " handle=\"%s\"",
+ entry->handle);
+
+ if (entry->mask & PMASK_SUBJECT)
+ g_string_append_escaped_printf(mas->buffer, " subject=\"%s\"",
+ entry->subject);
+
+ if (entry->mask & PMASK_DATETIME)
+ g_string_append_escaped_printf(mas->buffer, " datetime=\"%s\"",
+ entry->datetime);
+
+ if (entry->mask & PMASK_SENDER_NAME)
+ g_string_append_escaped_printf(mas->buffer,
+ " sender_name=\"%s\"",
+ entry->sender_name);
+
+ if (entry->mask & PMASK_SENDER_ADDRESSING)
+ g_string_append_escaped_printf(mas->buffer,
+ " sender_addressing=\"%s\"",
+ entry->sender_addressing);
+
+ if (entry->mask & PMASK_REPLYTO_ADDRESSING)
+ g_string_append_escaped_printf(mas->buffer,
+ " replyto_addressing=\"%s\"",
+ entry->replyto_addressing);
+
+ if (entry->mask & PMASK_RECIPIENT_NAME)
+ g_string_append_escaped_printf(mas->buffer,
+ " recipient_name=\"%s\"",
+ entry->recipient_name);
+
+ if (entry->mask & PMASK_RECIPIENT_ADDRESSING)
+ g_string_append_escaped_printf(mas->buffer,
+ " recipient_addressing=\"%s\"",
+ entry->recipient_addressing);
+
+ if (entry->mask & PMASK_TYPE)
+ g_string_append_escaped_printf(mas->buffer, " type=\"%s\"",
+ entry->type);
+
+ if (entry->mask & PMASK_RECEPTION_STATUS)
+ g_string_append_escaped_printf(mas->buffer,
+ " reception_status=\"%s\"",
+ entry->reception_status);
+
+ if (entry->mask & PMASK_SIZE)
+ g_string_append_escaped_printf(mas->buffer, " size=\"%s\"",
+ entry->size);
+
+ if (entry->mask & PMASK_ATTACHMENT_SIZE)
+ g_string_append_escaped_printf(mas->buffer,
+ " attachment_size=\"%s\"",
+ entry->attachment_size);
+
+ if (entry->mask & PMASK_TEXT)
+ g_string_append_escaped_printf(mas->buffer, " text=\"%s\"",
+ yesorno(entry->text));
+
+ if (entry->mask & PMASK_READ)
+ g_string_append_escaped_printf(mas->buffer, " read=\"%s\"",
+ yesorno(entry->read));
+
+ if (entry->mask & PMASK_SENT)
+ g_string_append_escaped_printf(mas->buffer, " sent=\"%s\"",
+ yesorno(entry->sent));
+
+ if (entry->mask & PMASK_PROTECTED)
+ g_string_append_escaped_printf(mas->buffer, " protected=\"%s\"",
+ yesorno(entry->protect));
+
+ if (entry->mask & PMASK_PRIORITY)
+ g_string_append_escaped_printf(mas->buffer, " priority=\"%s\"",
+ yesorno(entry->priority));
+
+ g_string_append(mas->buffer, "/>\n");
+
+proceed:
+ if (err != -EAGAIN)
+ obex_object_set_io_flags(mas, G_IO_IN, 0);
+}
+
static void get_folder_listing_cb(void *session, int err, uint16_t size,
const char *name, void *user_data)
{
@@ -311,6 +429,31 @@ static void *folder_listing_open(const char *name, int oflag, mode_t mode,
return mas;
}

+static void *msg_listing_open(const char *name, int oflag, mode_t mode,
+ void *driver_data, size_t *size, int *err)
+{
+ struct mas_session *mas = driver_data;
+ struct messages_filter filter = { 0, };
+
+ DBG("");
+
+ if (oflag != O_RDONLY) {
+ *err = -EBADR;
+ return NULL;
+ }
+
+ *err = messages_get_messages_listing(mas->backend_data, name, 0xffff, 0,
+ &filter,
+ get_messages_listing_cb, mas);
+
+ mas->buffer = g_string_new("");
+
+ if (*err < 0)
+ return NULL;
+ else
+ return mas;
+}
+
static void *any_open(const char *name, int oflag, mode_t mode,
void *driver_data, size_t *size, int *err)
{
@@ -405,7 +548,7 @@ static struct obex_mime_type_driver mime_msg_listing = {
.target = MAS_TARGET,
.target_size = TARGET_SIZE,
.mimetype = "x-bt/MAP-msg-listing",
- .open = any_open,
+ .open = msg_listing_open,
.close = any_close,
.read = any_read,
.write = any_write,
diff --git a/plugins/messages-dummy.c b/plugins/messages-dummy.c
index 408651e..b0b74d7 100644
--- a/plugins/messages-dummy.c
+++ b/plugins/messages-dummy.c
@@ -154,9 +154,7 @@ int messages_get_folder_listing(void *session,
int messages_get_messages_listing(void *session,
const char *name,
uint16_t max, uint16_t offset, struct messages_filter *filter,
- void (*callback)(void *session, int err, uint16_t size,
- gboolean newmsg, const struct messages_message *message,
- void *user_data),
+ messages_get_messages_listing_cb callback,
void *user_data)
{
return -EINVAL;
diff --git a/plugins/messages.h b/plugins/messages.h
index 5b0fd2d..f931eb4 100644
--- a/plugins/messages.h
+++ b/plugins/messages.h
@@ -223,12 +223,15 @@ int messages_get_folder_listing(void *session,
* Callback shall be called for every entry of the listing, giving message data
* in 'message'.
*/
+typedef void (*messages_get_messages_listing_cb)(void *session, int err,
+ uint16_t size, gboolean newmsg,
+ const struct messages_message *message,
+ void *user_data);
+
int messages_get_messages_listing(void *session,
const char *name,
uint16_t max, uint16_t offset, struct messages_filter *filter,
- void (*callback)(void *session, int err, uint16_t size,
- gboolean newmsg, const struct messages_message *message,
- void *user_data),
+ messages_get_messages_listing_cb callback,
void *user_data);

#define MESSAGES_ATTACHMENT (1 << 0)
--
1.7.4.1


2011-09-02 08:57:41

by Slawomir Bochenski

[permalink] [raw]
Subject: [PATCH obexd 2/5] MAP: Fix type of read_status in message_filter

---
plugins/messages.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/plugins/messages.h b/plugins/messages.h
index d9348c7..5b0fd2d 100644
--- a/plugins/messages.h
+++ b/plugins/messages.h
@@ -113,7 +113,7 @@ struct messages_filter {
uint8_t type;
char *period_begin;
char *period_end;
- uint8_t *read_status;
+ uint8_t read_status;
char *recipient;
char *originator;
uint8_t priority;
--
1.7.4.1