vici: Raise events with an optional identifier for specific connections
authorMartin Willi <martin@revosec.ch>
Mon, 10 Feb 2014 16:09:01 +0000 (17:09 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 7 May 2014 12:13:35 +0000 (14:13 +0200)
src/libcharon/plugins/vici/suites/test_event.c
src/libcharon/plugins/vici/suites/test_request.c
src/libcharon/plugins/vici/vici_dispatcher.c
src/libcharon/plugins/vici/vici_dispatcher.h

index 771f127..4dd9c73 100644 (file)
@@ -55,7 +55,7 @@ START_TEST(test_event)
        ck_assert(vici_register(conn, "test", event_cb, &count) == 0);
        ck_assert(vici_register(conn, "nonexistent", event_cb, &count) != 0);
 
-       dispatcher->raise_event(dispatcher, "test", vici_message_create_from_args(
+       dispatcher->raise_event(dispatcher, "test", 0, vici_message_create_from_args(
                 VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
                VICI_END));
 
@@ -100,7 +100,7 @@ START_TEST(test_stress)
                /* do some event re/deregistration in between */
                ck_assert(vici_register(conn, "dummy", event_cb, NULL) == 0);
 
-               dispatcher->raise_event(dispatcher, "test",
+               dispatcher->raise_event(dispatcher, "test", 0,
                        vici_message_create_from_args(
                                 VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
                                VICI_END));
index 1f124d3..8cb11a7 100644 (file)
@@ -188,7 +188,7 @@ START_TEST(test_stress)
        {
                /* do some event management in between */
                ck_assert(vici_register(conn, "dummy", event_cb, &events) == 0);
-               dispatcher->raise_event(dispatcher, "dummy",
+               dispatcher->raise_event(dispatcher, "dummy", 0,
                        vici_message_create_from_args(
                                 VICI_KEY_VALUE, "key1", chunk_from_str("value1"),
                                VICI_END));
index 797e51f..982206a 100644 (file)
@@ -382,11 +382,12 @@ METHOD(vici_dispatcher_t, manage_event, void,
 }
 
 METHOD(vici_dispatcher_t, raise_event, void,
-       private_vici_dispatcher_t *this, char *name, vici_message_t *message)
+       private_vici_dispatcher_t *this, char *name, u_int id,
+       vici_message_t *message)
 {
        enumerator_t *enumerator;
        event_t *event;
-       u_int *id;
+       u_int *current;
 
        this->mutex->lock(this->mutex);
        event = this->events->get(this->events, name);
@@ -397,9 +398,12 @@ METHOD(vici_dispatcher_t, raise_event, void,
        this->mutex->unlock(this->mutex);
 
        enumerator = array_create_enumerator(event->clients);
-       while (enumerator->enumerate(enumerator, &id))
+       while (enumerator->enumerate(enumerator, &current))
        {
-               send_op(this, *id, VICI_EVENT, name, message);
+               if (id == 0 || id == *current)
+               {
+                       send_op(this, *current, VICI_EVENT, name, message);
+               }
        }
        enumerator->destroy(enumerator);
 
index 5185504..effe5a6 100644 (file)
@@ -92,12 +92,13 @@ struct vici_dispatcher_t {
        void (*manage_event)(vici_dispatcher_t *this, char *name, bool reg);
 
        /**
-        * Raise an event to all clients registered to that event.
+        * Raise an event to a specific or all clients registered to that event.
         *
         * @param name                  event name to raise
+        * @param id                    client connection ID, 0 for all
         * @param message               event message to send, gets destroyed
         */
-       void (*raise_event)(vici_dispatcher_t *this, char *name,
+       void (*raise_event)(vici_dispatcher_t *this, char *name, u_int id,
                                                vici_message_t *message);
 
        /**