1 /* 2 * ProFTPD - FTP server daemon 3 * Copyright (c) 2003-2016 The ProFTPD Project team 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. 18 * 19 * As a special exemption, The ProFTPD Project team and other respective 20 * copyright holders give permission to link this program with OpenSSL, and 21 * distribute the resulting executable, without including the source code for 22 * OpenSSL in the source distribution. 23 */ 24 25 /* Event management */ 26 27 #ifndef PR_EVENT_H 28 #define PR_EVENT_H 29 30 /* Register a handler for the given event. The registered handler 31 * callback function takes two arguments: a pointer to some event-specific 32 * data and a pointer to some user-defined data. This user-defined data 33 * is set as the last argument in this registration function, and may be 34 * NULL. 35 * 36 * The return value is zero if the registration succeeded, and -1 if 37 * there was an error (in which case, errno will be set appropriately). 38 * 39 * Note that the registered event name is assumed to be a string constant; 40 * the Event API stores a pointer to the given string, not a duplicate 41 * of it. 42 */ 43 int pr_event_register(module *m, const char *event, 44 void (*cb)(const void *, void *), void *user_data); 45 46 /* Remove the given event handler from the event registration lists. The 47 * return value is zero if successful, and -1 if there was an error (in 48 * which case, errno will be set appropriately). 49 * 50 * If the module pointer is non-NULL, the event handler being unregistered 51 * must have been registered by that module. If the event name is 52 * non-NULL, then only the handler for that specific event is unregistered; 53 * otherwise, all events for the given module will be unregistered. If the 54 * callback pointer is non-NULL, the event handler being unregistered must be 55 * that specific handler. 56 * 57 * This arrangement means that it is possible, though considered terribly 58 * impolite, for the caller to unregister all handlers for a given event, 59 * regardless of registree, using: 60 * 61 * pr_event_unregister(NULL, event_name, NULL); 62 * 63 * Although rare, there are cases where this kind of blanket unregistration 64 * is necessary. More common will be the case where a module needs to 65 * unregister all of its event listeners at once: 66 * 67 * pr_event_unregister(&my_module, NULL, NULL); 68 */ 69 int pr_event_unregister(module *m, const char *event, 70 void (*cb)(const void *, void *)); 71 72 /* Generate an event. The named event is dispatched to any handlers that 73 * have registered an interest in handling this event. Any event-specific 74 * data is sent to the registered handlers. 75 */ 76 void pr_event_generate(const char *event, const void *event_data); 77 78 /* Returns the number of registered listeners for the given event, 79 * or -1 (with errno set appropriately) if there was an error. 80 */ 81 int pr_event_listening(const char *event); 82 83 /* Dump Events information. */ 84 void pr_event_dump(void (*)(const char *, ...)); 85 86 #endif /* PR_EVENT_H */ 87