/** Removes a remote from the server * \relates adbus_Server */ void adbus_remote_disconnect(adbus_Remote* r) { if (r == NULL) return; adbus_Server* s = r->server; dl_remove(Remote, r, &r->hl); // Free the matches struct Match* m = r->matches.next; while (m) { struct Match* next = m->hl.next; adbusI_serv_freematch(m); m = next; } dl_clear(Match, &r->matches); while (dv_size(&r->services) > 0) { adbusI_serv_releasename(s, r, dv_a(&r->services, 0)->name); } dv_free(Service, &r->services); adbus_buf_free(r->msg); adbus_buf_free(r->dispatch); ds_free(&r->unique); free(r); }
bool dl_del(list_t *list, char *new_word){ check_debug(list != NULL, "List is NULL."); check_debug(list->prev != NULL && list->next != NULL, "List is empty."); check_debug(list->prev != list && list->next != list, "List is empty."); list_t *node = NULL; node = list->next; bool result = 0; while(node != list){ list_t *next_node = node->next; check_debug(next_node != NULL && node->prev != NULL, "Invalid list, node: %s, node->prev: %s", next_node == NULL ? "NULL" : "VALID", node->prev == NULL ? "NULL" : "VALID"); if(strcmp(node->word,new_word) == 0){ check_debug(dl_remove(list, node) == 1, "Could not delete node."); result = 1; } node = next_node; } return result; error: return 0; }
bool dl_pop_back(list_t *list){ check_debug(list != NULL, "List is NULL."); check_debug(list->prev != NULL && list->prev != list, "List is empty."); check_debug(dl_remove(list, list->prev) == 1, "Delete from back was not successful."); return 1; error: return 0; }
bool dl_pop_front(list_t *list){ check_debug(list != NULL, "List is NULL."); check_debug(list->next != NULL && list->next != list, "List is empty."); check_debug(dl_remove(list, list->next) == 1, "Delete from front was not successful."); return 1; error: return 0; }
static void dl_remove_test(void) { printsln((String)__func__); List ac, ex; ac = dl_of_string("1, 2, 3, 4, 5, 6"); dl_remove(ac, 0); ex = dl_of_string("2, 3, 4, 5, 6"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("1, 2, 3, 4, 5, 6"); dl_remove(ac, 5); ex = dl_of_string("1, 2, 3, 4, 5"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("1, 2, 3, 4, 5, 6"); dl_remove(ac, 3); ex = dl_of_string("1, 2, 3, 5, 6"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("1"); dl_remove(ac, -1); ex = dl_of_string("1"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("1"); dl_remove(ac, 1); ex = dl_of_string("1"); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string("1"); dl_remove(ac, 0); ex = dl_of_string(""); dl_check_within(ac, ex); l_free(ac); l_free(ex); ac = dl_of_string(""); dl_remove(ac, 0); ex = dl_of_string(""); dl_check_within(ac, ex); l_free(ac); l_free(ex); }
bool dl_clear_list(list_t *list){ check_debug(list != NULL, "List is NULL."); if(list->prev != NULL && list->next != NULL && list->prev != list && list->next != list){ list_t *delete_node = NULL; delete_node = list->prev; while(delete_node != list){ list_t *prev_node; prev_node = delete_node->prev; check_debug(prev_node != NULL && delete_node->next != NULL, "Invalid list, prev_node: %s, delete_node->next: %s", prev_node == NULL ? "NULL" : "VALID", delete_node->next == NULL ? "NULL" : "VALID"); check_debug(dl_remove(list, delete_node) == 1, "Could not clear list."); delete_node = prev_node; } } return 1; error: return 0; }