Skip to content

Commit

Permalink
New NewMissedCalls added for phonebook_pull.
Browse files Browse the repository at this point in the history
NewMissedCalls is added to MCH phone book pull function for tracker
back-end (see PBAP specification pp.25,41). A new query is added to
phonebook-tracker.c result of which is at most 40 sorted by time and
date phone numbers from missed calls history with read/not read flags.

New missed calls are acquired from the list locally. This query is
submitted always first in order to have data for the first OBEX packet
(see PBAP specification p.33).

Canceling of pending D-Bus call was changed to conform introduced
modifications. More specifically, phonebook_pull, phonebook_get_entry,
phonebook_create_cache functions return pointer to phonebook_data
structure that holds D-Bus pending call instead of pointer to the call.

phonebook_data memory deallocation is moved to finalize function. This
data is not freed after each query since two successive queries may be
carried out and this structure holds pointer to the corresponding requests.

pbap.c and obex.c are updated to add NewMissedCalls application parameter
to first response OBEX packet. It is done only in the case when number of
new missed calls is larger than 0. Therefore, other than tracker phone
book back-ends are not affected.

mimetype.h, filesystem.c, irmc.c, nokia-backup.c, syncevolution.c are
updated to return flag parameter. OBEX_FL_FIT_ONE_PACKET flag is set only
for PBAP if number of new missed calls larger than 0 when pulling
phone book.

write_offset field is added to struct obex_session in obex-priv.h. It
holds write offset for TX OBEX packet and cannot be larger than tx_mtu.
It is used in obex.c when writing to a stream packets that may contain
headers of different types marked with OBEX_FL_FIT_ONE_PACKET flag.
  • Loading branch information
Dmitriy Paliy authored and Johan Hedberg committed Jan 3, 2011
1 parent b521c83 commit e0b3283
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 48 deletions.
16 changes: 13 additions & 3 deletions plugins/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,17 @@ static int filesystem_close(void *object)
}

static ssize_t filesystem_read(void *object, void *buf, size_t count,
uint8_t *hi)
uint8_t *hi, unsigned int *flags)
{
ssize_t ret;

ret = read(GPOINTER_TO_INT(object), buf, count);
if (ret < 0)
return -errno;

if (flags)
*flags = 0;

*hi = OBEX_HDR_BODY;

return ret;
Expand Down Expand Up @@ -499,17 +502,24 @@ 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,
uint8_t *hi, unsigned int *flags)
{
if (flags)
*flags = 0;

*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)
uint8_t *hi, unsigned int *flags)
{
struct capability_object *obj = object;

if (flags)
*flags = 0;

*hi = OBEX_HDR_BODY;

if (obj->buffer)
Expand Down
6 changes: 5 additions & 1 deletion plugins/irmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ 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, uint8_t *hi,
unsigned int *flags)
{
struct irmc_session *irmc = object;
int len;
Expand All @@ -460,6 +461,9 @@ static ssize_t irmc_read(void *object, void *buf, size_t count, uint8_t *hi)
if (!irmc->buffer)
return -EAGAIN;

if (flags)
*flags = 0;

*hi = OBEX_HDR_BODY;
len = string_read(irmc->buffer, buf, count);
DBG("returning %d bytes", len);
Expand Down
6 changes: 5 additions & 1 deletion plugins/nokia-backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,17 @@ 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,
uint8_t *hi, unsigned int *flags)
{
struct backup_object *obj = object;
ssize_t ret = 0;

*hi = OBEX_HDR_BODY;

if (flags)
*flags = 0;

if (obj->pending_call) {
DBG("cmd = %s, IN WAITING STAGE", obj->cmd);
return -EAGAIN;
Expand Down
50 changes: 45 additions & 5 deletions plugins/pbap.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ struct pbap_session {
struct pbap_object {
GString *buffer;
GByteArray *aparams;
gboolean firstpacket;
struct pbap_session *session;
void *request;
};
Expand Down Expand Up @@ -240,6 +241,13 @@ static GByteArray *append_aparam_header(GByteArray *buf, uint8_t tag,

return g_byte_array_append(buf, aparam,
sizeof(struct aparam_header) + PHONEBOOKSIZE_LEN);
case NEWMISSEDCALLS_TAG:
hdr->tag = NEWMISSEDCALLS_TAG;
hdr->len = NEWMISSEDCALLS_LEN;
memcpy(hdr->val, val, NEWMISSEDCALLS_LEN);

return g_byte_array_append(buf, aparam,
sizeof(struct aparam_header) + NEWMISSEDCALLS_LEN);
default:
return buf;
}
Expand Down Expand Up @@ -267,6 +275,13 @@ static void phonebook_size_result(const char *buffer, size_t bufsize,
pbap->obj->aparams = append_aparam_header(pbap->obj->aparams,
PHONEBOOKSIZE_TAG, &phonebooksize);

if (missed > 0) {
DBG("missed %d", missed);

pbap->obj->aparams = append_aparam_header(pbap->obj->aparams,
NEWMISSEDCALLS_TAG, &missed);
}

obex_object_set_io_flags(pbap->obj, G_IO_IN, 0);
}

Expand All @@ -293,6 +308,16 @@ static void query_result(const char *buffer, size_t bufsize, int vcards,
pbap->obj->buffer = g_string_append_len(pbap->obj->buffer,
buffer, bufsize);

if (missed > 0) {
DBG("missed %d", missed);

pbap->obj->firstpacket = TRUE;

pbap->obj->aparams = g_byte_array_new();
pbap->obj->aparams = append_aparam_header(pbap->obj->aparams,
NEWMISSEDCALLS_TAG, &missed);
}

obex_object_set_io_flags(pbap->obj, G_IO_IN, 0);
}

Expand Down Expand Up @@ -489,9 +514,7 @@ static void cache_entry_done(void *user_data)
return;
}

/* Unref previous request, associated data will be freed. */
phonebook_req_finalize(pbap->obj->request);
/* Get new pointer to pending call. */
pbap->obj->request = phonebook_get_entry(pbap->folder, id,
pbap->params, query_result, pbap, &ret);
if (ret < 0)
Expand Down Expand Up @@ -933,7 +956,7 @@ static ssize_t array_read(GByteArray *array, void *buf, size_t count)
}

static ssize_t vobject_pull_read(void *object, void *buf, size_t count,
uint8_t *hi)
uint8_t *hi, unsigned int *flags)
{
struct pbap_object *obj = object;
struct pbap_session *pbap = obj->session;
Expand All @@ -947,16 +970,27 @@ static ssize_t vobject_pull_read(void *object, void *buf, size_t count,
if (pbap->params->maxlistcount == 0) {
/* PhoneBookSize */
*hi = OBEX_HDR_APPARAM;
if (flags)
*flags = 0;
return array_read(obj->aparams, buf, count);
} else if (obj->firstpacket) {
/* NewMissedCalls */
*hi = OBEX_HDR_APPARAM;
obj->firstpacket = FALSE;
if (flags)
*flags = OBEX_FL_FIT_ONE_PACKET;
return array_read(obj->aparams, buf, count);
} else {
/* Stream data */
*hi = OBEX_HDR_BODY;
if (flags)
*flags = 0;
return string_read(obj->buffer, buf, count);
}
}

static ssize_t vobject_list_read(void *object, void *buf, size_t count,
uint8_t *hi)
uint8_t *hi, unsigned int *flags)
{
struct pbap_object *obj = object;
struct pbap_session *pbap = obj->session;
Expand All @@ -968,6 +1002,9 @@ static ssize_t vobject_list_read(void *object, void *buf, size_t count,
if (!pbap->cache.valid)
return -EAGAIN;

if (flags)
*flags = 0;

if (pbap->params->maxlistcount == 0) {
*hi = OBEX_HDR_APPARAM;
return array_read(obj->aparams, buf, count);
Expand All @@ -978,7 +1015,7 @@ static ssize_t vobject_list_read(void *object, void *buf, size_t count,
}

static ssize_t vobject_vcard_read(void *object, void *buf, size_t count,
uint8_t *hi)
uint8_t *hi, unsigned int *flags)
{
struct pbap_object *obj = object;

Expand All @@ -987,6 +1024,9 @@ static ssize_t vobject_vcard_read(void *object, void *buf, size_t count,
if (!obj->buffer)
return -EAGAIN;

if (flags)
*flags = 0;

*hi = OBEX_HDR_BODY;
return string_read(obj->buffer, buf, count);
}
Expand Down
Loading

0 comments on commit e0b3283

Please sign in to comment.