Cancel pending phonebook request
v3 cover Cancel pending phonebook request
Hi,
This is updated version of patch to handle pending phonebook request and to cancel it if OBEX session is terminated.
Additionally to previous submission, it containts updates for phonebook-dummy.c and phonebook-ebook.c backend drivers. Therefore, it is highly encouraged for those who exploit them to provide feedback.
Also, code for tracker was significantly improved.
BR,
Dmitriy
PATCH v3 1/3 Unified ebook data structures
Query data structures are unified in phonebook-ebook.c to have a unique identifier for ebook async operation. Purpose of this modification is next commit where pending async operation can be cancelled.
--- plugins/phonebook-ebook.c | 36 ++++++++++++++++-------------------- 1 files changed, 16 insertions(+), 20 deletions(-)
plugins/phonebook-ebook.c +16 -20
@@ -45,13 +45,9 @@#define QUERY_NAME "(contains \"given_name\" \"%s\")"#define QUERY_PHONE "(contains \"phone\" \"%s\")" -struct contacts_query { +struct context_query {const struct apparam_field *params; -phonebook_cb cb; -void *user_data; -}; - -struct cache_query { +phonebook_cb contacts_cb;phonebook_entry_cb entry_cb;phonebook_cache_ready_cb ready_cb;void *user_data;
@@ -141,7 +137,7 @@ static char *evcard_to_string(EVCard *evcard, unsigned int format,static void ebookpull_cb (EBook *book,EBookStatus estatus,GList *contacts,void *user_data) { -struct contacts_query *data = user_data; +struct context_query *data = user_data;GString *string =g_string_new ("" );unsigned int count =0 , maxcount;GList *l;
@@ -182,7 +178,7 @@ static void ebookpull_cb(EBook *book, EBookStatus estatus, GList *contacts, done: - data->cb (string->str, string->len, count,0 , data->user_data); + data->contacts_cb (string->str, string->len, count,0 , data->user_data);g_string_free (string, TRUE);g_free (data);
@@ -191,14 +187,14 @@ done:static void ebook_entry_cb (EBook *book,EBookStatus estatus,EContact *contact,void *user_data) { -struct contacts_query *data = user_data; +struct context_query *data = user_data;EVCard *evcard;char *vcard;size_t len;if (estatus !=E_BOOK_ERROR_OK ) {error ("E-Book query failed: status %d" , estatus); - data->cb (NULL ,0 ,1 ,0 , data->user_data); + data->contacts_cb (NULL ,0 ,1 ,0 , data->user_data);g_free (data);return ; }
@@ -210,7 +206,7 @@ static void ebook_entry_cb(EBook *book, EBookStatus estatus, len = vcard ?strlen (vcard) :0 ; - data->cb (vcard, len,1 ,0 , data->user_data); + data->contacts_cb (vcard, len,1 ,0 , data->user_data);g_free (vcard);g_free (data);
@@ -249,7 +245,7 @@ static char *evcard_name_attribute_to_string(EVCard *evcard)static void cache_cb (EBook *book,EBookStatus estatus,GList *contacts,void *user_data) { -struct cache_query *data = user_data; +struct context_query *data = user_data;GList *l;if (estatus !=E_BOOK_ERROR_OK ) {
@@ -411,13 +407,13 @@ done:int phonebook_pull (const char *name,const struct apparam_field *params,phonebook_cb cb,void *user_data) { -struct contacts_query *data; +struct context_query *data;EBookQuery *query; query =e_book_query_any_field_contains ("" ); - data = g_new0(struct contacts_query, 1); - data->cb = cb; + data = g_new0(struct context_query, 1); + data->contacts_cb = cb; data->params = params; data->user_data = user_data;
@@ -432,10 +428,10 @@ int phonebook_get_entry(const char *folder, const char *id,const struct apparam_field *params, phonebook_cb cb, void *user_data) { - struct contacts_query *data; + struct context_query *data; - data = g_new0(struct contacts_query, 1); - data->cb = cb; + data = g_new0(struct context_query, 1); + data->contacts_cb = cb; data->params = params; data->user_data = user_data;
@@ -450,7 +446,7 @@ int phonebook_get_entry(const char *folder, const char *id,int phonebook_create_cache (const char *name,phonebook_entry_cb entry_cb,phonebook_cache_ready_cb ready_cb,void *user_data) { -struct cache_query *data; +struct context_query *data;EBookQuery *query;gboolean ret;
@@ -459,7 +455,7 @@ int phonebook_create_cache(const char *name, phonebook_entry_cb entry_cb, query =e_book_query_any_field_contains ("" ); - data = g_new0(struct cache_query, 1); + data = g_new0(struct context_query, 1); data->entry_cb = entry_cb; data->ready_cb = ready_cb; data->user_data = user_data;
Signature · 1 line
1.7.0.4
PATCH v3 2/3 Add handing of backend pending request
In reply to Dmitriy PaliyAdd phonebook_req_cancel function prototype in phonebook.h to cancel pending request if it is not completed, and to unref pointer to pending request if such is applicable.
It does the following, depending on phonebook backend:
- for phonebook-tracker.c backend driver, it cancels pending DBus call,
- for phonebook-dummy.c, it removes GSource with a given id,
- for phonebook-ebook.c, it cancels last, still running, asynchronous operation.
The following modifcations are donein the code. Phonebook request pointer is added in PBAP object and IRMC session data to provide reference for pending call. Phonebook callbacks are updated in PBAP and IRMC to unref request upon completion and clear pointers, if such is applicable.
PBAP and IRMC are updated to cancel pending request, if any, when OBEX object is closed.
Phonebook_pull, phonebook_get_entry, phonebook_create_cache functions are updated to return void pointer to backend specific request and error code. All backend drivers updated accordingly to the modified API, which are phonebook-tracker.c, phonebook-dummy.c, and phonebook-ebook.c, to be specific.
In phonebook-tracker.c, query_tracker is updated to return pending DBus call request. Allocated pending_reply and phonebook_data are destroyed after call is unrefed. For this purpose new query_free_data function is created.
Call is unrefed either if request succeeded or in phonebook_req_cancel if terminated.
Such fix prevents obexd crash on unexpected OBEX session close. E.g., OBEX session is closed before reply comes from phonebook backend. In that case, both session and object are destroyed, and dereferencing of object in associated callback function causes crash.
--- plugins/irmc.c | 27 ++++++++--- plugins/pbap.c | 69 ++++++++++++++++++++------ plugins/phonebook-dummy.c | 70 +++++++++++++++++++-------- plugins/phonebook-ebook.c | 95 +++++++++++++++++++++++++++++------- plugins/phonebook-tracker.c | 113 ++++++++++++++++++++++++++++++++---------- plugins/phonebook.h | 17 ++++-- 6 files changed, 296 insertions(+), 95 deletions(-)
plugins/irmc.c +20 -7
@@ -110,6 +110,7 @@ struct irmc_session {char did[DID_LEN ];char manu[DID_LEN ];char model[DID_LEN ]; +void *request; };#define IRMC_TARGET_SIZE 9
@@ -139,6 +140,11 @@ static void phonebook_size_result(const char *buffer, size_t bufsize,DBG ("vcards %d" , vcards); irmc->params->maxlistcount = vcards; + +if (irmc->request) { +phonebook_req_cancel (irmc->request); + irmc->request =NULL ; + } } static void query_result(const char *buffer, size_t bufsize, int vcards,
@@ -149,6 +155,11 @@ static void query_result(const char *buffer, size_t bufsize, int vcards,DBG ("bufsize %zu vcards %d missed %d" , bufsize, vcards, missed); +if (irmc->request) { +phonebook_req_cancel (irmc->request); + irmc->request =NULL ; + } +/* first add a 'owner' vcard */ if (!irmc->buffer) irmc->buffer =g_string_new (owner_vcard);
@@ -210,11 +221,8 @@ static void *irmc_connect(struct obex_session *os, int *err) param->maxlistcount =0 ;/* to count the number of vcards... */ param->filter =0x200085 ;/* UID TEL N VERSION */ irmc->params = param; -phonebook_pull ("telecom/pb.vcf" , irmc->params, phonebook_size_result, - irmc); - -if (err) - *err =0 ; + irmc->request =phonebook_pull ("telecom/pb.vcf" , irmc->params, + phonebook_size_result, irmc, err);return irmc; }
@@ -298,8 +306,8 @@ static void *irmc_open_pb(const char *name, struct irmc_session *irmc,if (!g_strcmp0 (name,".vcf" )) {/* how can we tell if the vcard count call already finished? */ - ret =phonebook_pull ("telecom/pb.vcf" , irmc->params, - query_result, irmc); + irmc->request =phonebook_pull ("telecom/pb.vcf" , irmc->params, + query_result, irmc, &ret);if (ret <0 ) {DBG ("phonebook_pull failed..." ); goto fail;
@@ -435,6 +443,11 @@ static int irmc_close(void *object) irmc->buffer =NULL ; } +if (irmc->request) { +phonebook_req_cancel (irmc->request); + irmc->request =NULL ; + } +return 0 ; }
plugins/pbap.c +53 -16
162 lines not on this page · raw message
plugins/phonebook-dummy.c +49 -21
133 lines not on this page · raw message
plugins/phonebook-ebook.c +77 -18
178 lines not on this page · raw message
plugins/phonebook-tracker.c +86 -27
213 lines not on this page · raw message
plugins/phonebook.h +11 -6
@@ -86,8 +86,8 @@ char *phonebook_set_folder(const char *current_folder,* entries of a given folder. The back-end MUST return only the content based * on the application parameters requested by the client. */ -int phonebook_pull (const char *name,const struct apparam_field *params, -phonebook_cb cb,void *user_data); +void *phonebook_pull (const char *name,const struct apparam_field *params, +phonebook_cb cb,void *user_data,int *err);/* * Function used to retrieve a contact from the backend. Only contacts
@@ -95,9 +95,9 @@ int phonebook_pull(const char *name, const struct apparam_field *params,* return only the content based on the application parameters requested * by the client. */ -int phonebook_get_entry (const char *folder,const char *id, +void *phonebook_get_entry (const char *folder,const char *id,const struct apparam_field *params, -phonebook_cb cb,void *user_data); +phonebook_cb cb,void *user_data,int *err);/* * PBAP core will keep the contacts cache per folder. SetPhoneBook or
@@ -105,5 +105,10 @@ int phonebook_get_entry(const char *folder, const char *id,* Cache will store only the necessary information required to reply to * PullvCardListing request and verify if a given contact belongs to the source. */ -int phonebook_create_cache (const char *name,phonebook_entry_cb entry_cb, -phonebook_cache_ready_cb ready_cb,void *user_data); +void *phonebook_create_cache (const char *name,phonebook_entry_cb entry_cb, +phonebook_cache_ready_cb ready_cb,void *user_data,int *err); + +/* +* Cancels pending call to phonebook backend. +*/ +void phonebook_req_cancel (void *request);
Signature · 1 line
1.7.0.4
PATCH v3 3/3 Code clean-up: long, empty lines, indentation
In reply to Dmitriy PaliyLines longer 80 symbols and empty lines removed. Indentation in generate_response function corrected.
--- plugins/pbap.c | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-)
plugins/pbap.c +8 -9
@@ -273,8 +273,8 @@ static void query_result(const char *buffer, size_t bufsize, int vcards,if (!pbap->obj->buffer) pbap->obj->buffer =g_string_new_len (buffer, bufsize);else - pbap->obj->buffer =g_string_append_len (pbap->obj->buffer, buffer, - bufsize); + pbap->obj->buffer =g_string_append_len (pbap->obj->buffer, + buffer, bufsize);obex_object_set_io_flags (pbap->obj,G_IO_IN ,0 ); }
@@ -418,9 +418,8 @@ static int generate_response(void *user_data)* only the reference for the "real" cache entry. */ sorted =sort_entries (pbap->cache.entries, pbap->params->order, - pbap->params->searchattrib, - (const char *) pbap->params->searchval); - + pbap->params->searchattrib, + (const char *) pbap->params->searchval);if (sorted ==NULL )return -ENOENT ;
@@ -431,12 +430,12 @@ static int generate_response(void *user_data)for (; l && max; l = l->next, max--) {const struct cache_entry *entry = l->data; -g_string_append_printf (pbap->obj->buffer,VCARD_LISTING_ELEMENT , - entry->handle, entry->name); +g_string_append_printf (pbap->obj->buffer, +VCARD_LISTING_ELEMENT , entry->handle, entry->name); } - pbap->obj->buffer =g_string_append (pbap->obj->buffer,VCARD_LISTING_END ); - + pbap->obj->buffer =g_string_append (pbap->obj->buffer, +VCARD_LISTING_END );g_slist_free (sorted);return 0 ;
Signature · 1 line
1.7.0.4