int cometd_unsubscribe(const cometd* h, cometd_subscription* s) { g_return_val_if_fail(s != NULL, ECOMETD_UNKNOWN); g_return_val_if_fail(s->channel != NULL, ECOMETD_UNKNOWN); const char* channel = s->channel; int code = ECOMETD_UNKNOWN; JsonNode* node; /* We can't unsubscribe from a remote meta channel and we only want to remotely unsubscribe if this is the last remaining listener. */ if (cometd_is_meta_channel(channel) == FALSE && cometd_listener_count(h, channel) == 1) { JsonNode* node = cometd_new_unsubscribe_message(h, channel); if (node != NULL) { code = cometd_transport_send(h, node); json_node_free(node); } } // don't remove the local listener if the remote call failed if (code != COMETD_SUCCESS) code = cometd_remove_listener(h, s); return code; }
END_TEST START_TEST (test_cometd_new_unsubscribe_message) { cometd_conn_set_client_id(g_instance->conn, "testid"); const char* expected_channel = "/foo/bar/baz"; JsonNode* msg = cometd_new_unsubscribe_message(g_instance, expected_channel); JsonObject* obj = json_node_get_object(msg); const gchar* actual_channel = json_object_get_string_member(obj, COMETD_MSG_SUBSCRIPTION_FIELD); ck_assert_str_eq(expected_channel, actual_channel); json_node_free(msg); }