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_MOD_H__
26 #define __WZD_MOD_H__
27 
28 typedef enum {
29   EVENT_IGNORED=0,
30   EVENT_NEXT,       /**< pass event to next handler */
31   EVENT_HANDLED,
32   EVENT_ERR
33 } wzd_hook_reply_t;
34 
35 /* free hook list */
36 void hook_free(wzd_hook_t **hook_list);
37 
38 /** \brief register a new hook
39  * \deprecated use \ref event_connect_function
40  */
41 int hook_add(wzd_hook_t ** hook_list, unsigned long mask, void_fct hook) DEPRECATED;
42 
43 /** \brief register a new hook to an external command
44  * \deprecated use \ref event_connect_external
45  */
46 int hook_add_external(wzd_hook_t ** hook_list, unsigned long mask, const char *command) DEPRECATED;
47 
48 
49 typedef struct protocol_handler_t protocol_handler_t;
50 
51 typedef int (*fcn_handler)(const char*, const char *);
52 
53 struct protocol_handler_t {
54   char *sig;
55   unsigned int siglen;
56   fcn_handler handler;
57   protocol_handler_t * next_proto;
58 };
59 
60 
61 /** \brief registers a new protocol-like handler for hooks.
62  * ex: tcl:/path/to/file
63  */
64 int hook_add_protocol(const char *signature, unsigned int sig_len, fcn_handler handler);
65 
66 /** \brief Free memory used by registered protocols */
67 void hook_free_protocols(void);
68 
69 /** \brief Check if string starts with a known protocol
70  * \return The protocol handler if ok
71  */
72 protocol_handler_t * hook_check_protocol(const char *str);
73 
74 /** remove hook from list */
75 int hook_remove(wzd_hook_t **hook_list, unsigned long mask, void_fct hook);
76 
77 /** \deprecated Use \ref event_exec */
78 int hook_call_external(wzd_hook_t *hook, unsigned int code) DEPRECATED;
79 
80 unsigned int hook_get_current_reply_code(void);
81 
82 char * event2str(const unsigned long mask);
83 unsigned long str2event(const char *s);
84 
85 #define FORALL_HOOKS(test_mask)	{ \
86   wzd_hook_t * hook; \
87   for (hook = mainConfig->hook; hook; hook = hook->next_hook) \
88   { \
89     if (hook->mask & (test_mask)) { \
90 
91 #define	END_FORALL_HOOKS	}\
92   }\
93 }
94 
95 /* module hook struct, used in modules */
96 typedef struct {
97   unsigned long event_id;
98   void_fct fct;
99 } module_hook_t;
100 
101 /* check a module file */
102 int module_check(const char *filename);
103 
104 /* add a module to the list */
105 int module_add(wzd_module_t ** module_list, const char * name);
106 
107 /* load a module - module really should have been checked before ! */
108 int module_load(wzd_module_t *module);
109 
110 /** unload module, and remove it from list */
111 int module_unload(wzd_module_t **module_list, const char *name);
112 
113 /* free module list */
114 void module_free(wzd_module_t ** module_list);
115 
116 /** \brief Get module name */
117 const char * module_get_name(wzd_module_t * module);
118 
119 /** \brief Get module version */
120 const char * module_get_version(wzd_module_t * module);
121 
122 
123 #define MODULE_NAME(n)    const char * module_name = #n
124 #define MODULE_VERSION(v) const char * module_version = #v
125 
126 
127 /********************************/
128 /* modules functions prototypes */
129 
130 #define	WZD_MODULE_INIT		wzd_module_init
131 #define	STR_MODULE_INIT		"wzd_module_init"
132 typedef int (*fcn_module_init)(void);
133 
134 #define	WZD_MODULE_CLOSE	wzd_module_close
135 #define STR_MODULE_CLOSE	"wzd_module_close"
136 typedef int (*fcn_module_close)(void);
137 
138 #endif /* __WZD_MOD_H__ */
139