Annotation of embedaddon/strongswan/src/libcharon/plugins/vici/vici_dispatcher.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2013 Martin Willi
                      3:  * Copyright (C) 2013 revosec AG
                      4:  *
                      5:  * This program is free software; you can redistribute it and/or modify it
                      6:  * under the terms of the GNU General Public License as published by the
                      7:  * Free Software Foundation; either version 2 of the License, or (at your
                      8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                      9:  *
                     10:  * This program is distributed in the hope that it will be useful, but
                     11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     13:  * for more details.
                     14:  */
                     15: 
                     16: /*
                     17:  * Copyright (C) 2014 Timo Teräs <timo.teras@iki.fi>
                     18:  *
                     19:  * Permission is hereby granted, free of charge, to any person obtaining a copy
                     20:  * of this software and associated documentation files (the "Software"), to deal
                     21:  * in the Software without restriction, including without limitation the rights
                     22:  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
                     23:  * copies of the Software, and to permit persons to whom the Software is
                     24:  * furnished to do so, subject to the following conditions:
                     25:  *
                     26:  * The above copyright notice and this permission notice shall be included in
                     27:  * all copies or substantial portions of the Software.
                     28:  *
                     29:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
                     30:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
                     31:  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
                     32:  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
                     33:  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
                     34:  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
                     35:  * THE SOFTWARE.
                     36:  */
                     37: 
                     38: /**
                     39:  * @defgroup vici_dispatcher vici_dispatcher
                     40:  * @{ @ingroup vici
                     41:  */
                     42: 
                     43: #ifndef VICI_DISPATCHER_H_
                     44: #define VICI_DISPATCHER_H_
                     45: 
                     46: #include "vici_message.h"
                     47: 
                     48: typedef struct vici_dispatcher_t vici_dispatcher_t;
                     49: typedef enum vici_operation_t vici_operation_t;
                     50: 
                     51: /**
                     52:  * Default socket URI of vici service
                     53:  */
                     54: #ifdef WIN32
                     55: # define VICI_DEFAULT_URI "tcp://127.0.0.1:4502"
                     56: #else
                     57: # define VICI_DEFAULT_URI "unix://" IPSEC_PIDDIR "/charon.vici"
                     58: #endif
                     59: 
                     60: /**
                     61:  * Kind of vici operation
                     62:  */
                     63: enum vici_operation_t {
                     64:        /** a named request message */
                     65:        VICI_CMD_REQUEST,
                     66:        /** an unnamed response message to a request */
                     67:        VICI_CMD_RESPONSE,
                     68:        /** unnamed response if requested command is unknown */
                     69:        VICI_CMD_UNKNOWN,
                     70:        /** a named event registration request */
                     71:        VICI_EVENT_REGISTER,
                     72:        /** a named event unregistration request */
                     73:        VICI_EVENT_UNREGISTER,
                     74:        /** unnamed response for successful event (un-)registration */
                     75:        VICI_EVENT_CONFIRM,
                     76:        /** unnamed response if event (un-)registration failed */
                     77:        VICI_EVENT_UNKNOWN,
                     78:        /** a named event message */
                     79:        VICI_EVENT,
                     80: };
                     81: 
                     82: /**
                     83:  * Vici command callback function
                     84:  *
                     85:  * @param user                 user data, as supplied during registration
                     86:  * @param name                 name of the command it has been registered under
                     87:  * @param id                   client connection identifier
                     88:  * @param request              request message data
                     89:  * @return                             response message
                     90:  */
                     91: typedef vici_message_t* (*vici_command_cb_t)(void *user, char *name, u_int id,
                     92:                                                                                         vici_message_t *request);
                     93: 
                     94: /**
                     95:  * Vici command dispatcher.
                     96:  */
                     97: struct vici_dispatcher_t {
                     98: 
                     99:        /**
                    100:         * Register/Unregister a callback invoked for a specific command request.
                    101:         *
                    102:         * @param name                  name of the command
                    103:         * @param cb                    callback function to register, NULL to unregister
                    104:         * @param user                  user data to pass to callback
                    105:         */
                    106:        void (*manage_command)(vici_dispatcher_t *this, char *name,
                    107:                                                   vici_command_cb_t cb, void *user);
                    108: 
                    109:        /**
                    110:         * Register/Unregister an event type to send.
                    111:         *
                    112:         * The dispatcher internally manages event subscriptions. Clients registered
                    113:         * for an event will receive such messages when the event is raised.
                    114:         *
                    115:         * @param name                  event name to manager
                    116:         * @param reg                   TRUE to register, FALSE to unregister
                    117:         */
                    118:        void (*manage_event)(vici_dispatcher_t *this, char *name, bool reg);
                    119: 
                    120:        /**
                    121:         * Check if an event has listeners.
                    122:         *
                    123:         * This can be used to check if a vici message needs to be generated or not,
                    124:         * as in some cases the generation can be a heavy operation.
                    125:         *
                    126:         * @param name                  event name to check
                    127:         * @return                              TRUE if event has listeners
                    128:         */
                    129:        bool (*has_event_listeners)(vici_dispatcher_t *this, char *name);
                    130: 
                    131:        /**
                    132:         * Raise an event to a specific or all clients registered to that event.
                    133:         *
                    134:         * @param name                  event name to raise
                    135:         * @param id                    client connection ID, 0 for all
                    136:         * @param message               event message to send, gets destroyed
                    137:         */
                    138:        void (*raise_event)(vici_dispatcher_t *this, char *name, u_int id,
                    139:                                                vici_message_t *message);
                    140: 
                    141:        /**
                    142:         * Destroy a vici_dispatcher_t.
                    143:         */
                    144:        void (*destroy)(vici_dispatcher_t *this);
                    145: };
                    146: 
                    147: /**
                    148:  * Create a vici_dispatcher instance.
                    149:  *
                    150:  * @param uri          uri for listening stream service
                    151:  * @return                     dispatcher instance
                    152:  */
                    153: vici_dispatcher_t *vici_dispatcher_create(char *uri);
                    154: 
                    155: #endif /** VICI_DISPATCHER_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>