1 /* 2 * wzdftpd - a modular and cool ftp server 3 * Copyright (C) 2002-2004 Pierre Chifflier 4 * 5 * This program is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU General Public License 7 * as published by the Free Software Foundation; either version 2 8 * of the License, or (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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * As a special exemption, Pierre Chifflier 20 * and other respective copyright holders give permission to link this program 21 * with OpenSSL, and distribute the resulting executable, without including 22 * the source code for OpenSSL in the source distribution. 23 */ 24 25 #ifndef __WZD_EVENTS__ 26 #define __WZD_EVENTS__ 27 28 /** \file wzd_events.h 29 * \brief Connect events to callback functions 30 * 31 * \addtogroup libwzd_core 32 * @{ 33 */ 34 35 #include <libwzd-base/list.h> 36 37 typedef struct wzd_event_t wzd_event_t; 38 typedef struct wzd_event_manager_t wzd_event_manager_t; 39 40 typedef enum event_reply_t event_reply_t; 41 42 enum event_reply_t { 43 EVENT_OK = 0, /**< standard reply, continue processing events */ 44 EVENT_BREAK = 1, /**< event is ok, but stop processing events */ 45 EVENT_DENY = 2, /**< event is ok, but stop processing events and refuse commands */ 46 47 EVENT_ERROR = 255, /**< error while processing event */ 48 }; 49 50 #ifndef WIN32 51 52 typedef struct wzd_popen_t wzd_popen_t; 53 54 struct wzd_popen_t { 55 int child_pid; 56 int fdr; 57 }; 58 59 wzd_popen_t * wzd_popen(const char * command); 60 event_reply_t wzd_pclose(wzd_popen_t * p); 61 62 #endif /* WIN32 */ 63 64 typedef event_reply_t (*event_function_t)(const char * args); 65 66 struct wzd_event_t { 67 u32_t id; 68 69 70 event_function_t callback; 71 wzd_string_t * external_command; 72 73 74 wzd_string_t * params; 75 }; 76 77 struct wzd_event_manager_t { 78 List * event_list; 79 }; 80 81 /** \brief Initialize an allocated wzd_event_manager_t struct */ 82 void event_mgr_init(wzd_event_manager_t * mgr); 83 84 /** \brief Free memory used by a wzd_event_manager_t struct (the struct itself is not freed) */ 85 void event_mgr_free(wzd_event_manager_t * mgr); 86 87 /*** these are candidate prototypes ... work in progress */ 88 89 int event_connect_function(wzd_event_manager_t * mgr, u32_t event_id, event_function_t callback, wzd_string_t * params); 90 int event_connect_external(wzd_event_manager_t * mgr, u32_t event_id, wzd_string_t * external_command, wzd_string_t * params); 91 92 int event_send(wzd_event_manager_t * mgr, u32_t event_id, unsigned int reply_code, wzd_string_t * params, wzd_context_t * context); 93 94 /** \brief Execute command 95 * 96 * If \a command begins with a !, the string is interpreted as a file name 97 * which is sent to the client. If \a command begins by a known protocol 98 * identifier (e.g perl:) then the corresponding handler is executed. 99 * In other cases, the corresponding shell command is executed. 100 */ 101 event_reply_t event_exec(const char * commandline, wzd_context_t * context); 102 103 /** @} */ 104 105 #endif /* __WZD_EVENTS__ */ 106