Skip to content

Commit

Permalink
Merge pull request #8 from monich/null-task-id
Browse files Browse the repository at this point in the history
[mms_dispatcher] Beware of tasks with NULL ids
  • Loading branch information
Slava Monich committed Mar 21, 2014
2 parents e5d079c + 1ef49f8 commit 0068695
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mms-lib/src/mms_dispatcher.c
Expand Up @@ -532,11 +532,11 @@ mms_dispatcher_cancel(
GList* entry;
for (entry = disp->tasks->head; entry; entry = entry->next) {
MMSTask* task = entry->data;
if (!id || !strcmp(task->id, id)) {
if (mms_task_match_id(task, id)) {
mms_task_cancel(task);
}
}
if (disp->active_task && (!id || !strcmp(disp->active_task->id, id))) {
if (mms_task_match_id(disp->active_task, id)) {
mms_task_cancel(disp->active_task);
}
}
Expand Down
19 changes: 19 additions & 0 deletions mms-lib/src/mms_task.c
Expand Up @@ -298,6 +298,25 @@ mms_task_queue_and_unref(
return ok;
}

gboolean
mms_task_match_id(
MMSTask* task,
const char* id)
{
if (!task) {
/* No task - no match */
return FALSE;
} else if (!id || !id[0]) {
/* A wildcard matching any task */
return TRUE;
} else if (!task->id || !task->id[0]) {
/* Only wildcard will match that */
return FALSE;
} else {
return !strcmp(task->id, id);
}
}

/**
* Generates dummy task id if necessary.
*/
Expand Down
5 changes: 5 additions & 0 deletions mms-lib/src/mms_task.h
Expand Up @@ -144,6 +144,11 @@ mms_task_queue_and_unref(
MMSTaskDelegate* delegate,
MMSTask* task);

gboolean
mms_task_match_id(
MMSTask* task,
const char* id);

const char*
mms_task_make_id(
MMSTask* task);
Expand Down

0 comments on commit 0068695

Please sign in to comment.