END_TEST START_TEST (test_cometd_is_meta_channel) { fail_unless(cometd_is_meta_channel("/meta/*")); fail_unless(cometd_is_meta_channel("/meta/connect")); fail_if(cometd_is_meta_channel("/foo")); fail_if(cometd_is_meta_channel(NULL)); }
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; }
cometd_subscription* cometd_subscribe(const cometd* h, char* channel, cometd_callback handler) { int code = COMETD_SUCCESS; cometd_subscription* s = NULL; if (cometd_is_meta_channel(channel) == FALSE) { JsonNode* node = cometd_new_subscribe_message(h, channel); if (node != NULL) { code = cometd_transport_send(h, node); json_node_free(node); } } if (code == COMETD_SUCCESS) s = cometd_add_listener(h, channel, handler); return s; }