345a786f642086eef8e456c3022b0f3ae51d8345
[citadel.git] / citadel / include / ctdl_module.h
1 /* $Id$ */
2
3 #ifndef CTDL_MODULE_H
4 #define CTDL_MODULE_H
5
6 #include "sysdep.h"
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <fcntl.h>
11 #include <ctype.h>
12 #include <signal.h>
13 #include <pwd.h>
14 #include <errno.h>
15 #include <sys/types.h>
16
17 #if TIME_WITH_SYS_TIME
18 # include <sys/time.h>
19 # include <time.h>
20 #else
21 # if HAVE_SYS_TIME_H
22 #  include <sys/time.h>
23 # else
24 #  include <time.h>
25 # endif
26 #endif
27
28 #include <sys/wait.h>
29 #include <string.h>
30 #include <limits.h>
31
32
33 #ifndef HAVE_SNPRINTF
34 #include "snprintf.h"
35 #endif
36
37
38 #include <libcitadel.h>
39
40 #include "server.h"
41 #include "sysdep_decls.h"
42 #include "msgbase.h"
43 #include "threads.h"
44 /*
45  * define macros for module init stuff
46  */
47  
48 #define CTDL_MODULE_INIT(module_name) char *ctdl_module_##module_name##_init (int threading)
49
50 #define CTDL_INIT_CALL(module_name) ctdl_module_##module_name##_init (threading)
51
52 #define CTDL_MODULE_UPGRADE(module_name) char *ctdl_module_##module_name##_upgrade (void)
53
54 #define CTDL_UPGRADE_CALL(module_name) ctdl_module_##module_name##_upgrade ()
55
56
57 /*
58  * Prototype for making log entries in Citadel.
59  */
60
61 void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...);
62
63 #define CtdlAideMessage(TEXT, SUBJECT) quickie_message("Citadel",NULL,NULL,AIDEROOM,TEXT,FMT_CITADEL,SUBJECT) 
64
65 /*
66  * Hook functions available to modules.
67  */
68
69 void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType);
70 void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
71
72 void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
73 void CtdlUnregisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
74
75 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
76 void CtdlUnregisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
77
78 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
79                                                         int EventType);
80 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
81                                                         int EventType);
82
83 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
84 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
85
86 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
87 void CtdlUnregisterRoomHook(int (*fnc_ptr)(struct ctdlroom *) );
88
89 void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
90 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) );
91
92 void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
93 void CtdlUnregisterCleanupHook(void (*fcn_ptr)(void));
94
95 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
96
97 void CtdlRegisterServiceHook(int tcp_port,
98                              char *sockpath,
99                              void (*h_greeting_function) (void),
100                              void (*h_command_function) (void),
101                              void (*h_async_function) (void),
102                              const char *ServiceName
103 );
104 void CtdlUnregisterServiceHook(int tcp_port,
105                         char *sockpath,
106                         void (*h_greeting_function) (void),
107                         void (*h_command_function) (void),
108                         void (*h_async_function) (void)
109 );
110
111 void CtdlRegisterFixedOutputHook(char *content_type,
112                         void (*output_function) (char *supplied_data, int len)
113 );
114 void CtdlUnRegisterFixedOutputHook(char *content_type);
115
116 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
117
118 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name);
119
120
121 /*
122  * Directory services hooks for LDAP etc
123  */
124
125 #define DIRECTORY_USER_DEL 1    // Delete a user entry
126 #define DIRECTORY_CREATE_HOST 2 // Create a host entry if not already there.
127 #define DIRECTORY_CREATE_OBJECT 3       // Create a new object for directory entry
128 #define DIRECTORY_ATTRIB_ADD 4  // Add an attribute to the directory entry object
129 #define DIRECTORY_SAVE_OBJECT 5 // Save the object to the directory service
130 #define DIRECTORY_FREE_OBJECT 6 // Free the object and its attributes
131
132 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module);
133 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd);
134
135 /* TODODRW: This needs to be changed into a hook type interface
136  * for now we have this horrible hack
137  */
138 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
139
140
141 /*
142  * Citadel Threads API
143  */
144 struct CtdlThreadNode *CtdlThreadCreate(char *name, long flags, void *(*thread_func) (void *arg), void *args);
145 struct CtdlThreadNode *CtdlThreadSchedule(char *name, long flags, void *(*thread_func) (void *arg), void *args, time_t when);
146 void CtdlThreadSleep(int secs);
147 void CtdlThreadStop(struct CtdlThreadNode *thread);
148 int CtdlThreadCheckStop(void);
149 /* void CtdlThreadCancel2(struct CtdlThreadNode *thread); Leave this out, it should never be needed */
150 const char *CtdlThreadName(const char *name);
151 struct CtdlThreadNode *CtdlThreadSelf(void);
152 int CtdlThreadGetCount(void);
153 int CtdlThreadGetWorkers(void);
154 double CtdlThreadGetWorkerAvg(void);
155 double CtdlThreadGetLoadAvg(void);
156 void CtdlThreadGC(void);
157 void CtdlThreadStopAll(void);
158 int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
159 void CtdlThreadAllocTSD(void);
160
161 #define CTDLTHREAD_BIGSTACK     0x0001
162 #define CTDLTHREAD_WORKER       0x0002
163
164 /* Macros to speed up getting outr thread */
165
166 #define MYCURSORS       (((ThreadTSD*)pthread_getspecific(ThreadKey))->cursors)
167 #define MYTID           (((ThreadTSD*)pthread_getspecific(ThreadKey))->tid)
168 #define CT              (((ThreadTSD*)pthread_getspecific(ThreadKey))->self)
169
170 /** return the current context list as an array and do it in a safe manner
171  * The returned data is a copy so only reading is useful
172  * The number of contexts is returned in count.
173  * Beware, this does not copy any of the data pointed to by the context.
174  * This means that you can not rely on things like the redirect buffer being valid.
175  * You must free the returned pointer when done.
176  */
177 struct CitContext *CtdlGetContextArray (int *count);
178 void CtdlFillSystemContext(struct CitContext *context, char *name);
179
180 int CtdlTrySingleUser(void);
181 void CtdlEndSingleUser(void);
182 int CtdlWantSingleUser(void);
183 int CtdlIsSingleUser(void);
184
185
186 /*
187  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
188  * This provides a quick way to initialise a variable that might be used to indicate
189  * messages that should not be processed. EG. a new Sieve script will use this
190  * to record determine that messages older than this should not be processed.
191  * This function is defined in control.c
192  */
193 long CtdlGetCurrentMessageNumber(void);
194
195
196
197 /*
198  * Expose various room operation functions from room_ops.c to the modules API
199  */
200
201 unsigned CtdlCreateRoom(char *new_room_name,
202                         int new_room_type,
203                         char *new_room_pass,
204                         int new_room_floor,
205                         int really_create,
206                         int avoid_access,
207                         int new_room_view);
208 int CtdlGetRoom(struct ctdlroom *qrbuf, char *room_name);
209 int CtdlGetRoomLock(struct ctdlroom *qrbuf, char *room_name);
210 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr);
211 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
212                 int *result, int *view);
213 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
214 void CtdlForEachRoom(void (*CallBack)(struct ctdlroom *EachRoom, void *out_data),
215         void *in_data);
216 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
217 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
218 void CtdlUserGoto (char *where, int display_result, int transiently,
219                         int *msgs, int *new);
220 struct floor *CtdlGetCachedFloor(int floor_num);
221 void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf);
222 void CtdlGetFloor (struct floor *flbuf, int floor_num);
223 void CtdlPutFloor (struct floor *flbuf, int floor_num);
224 int CtdlIsNonEditable(struct ctdlroom *qrbuf);
225 void CtdlPutRoom(struct ctdlroom *);
226
227 /*
228  * Possible return values for CtdlRenameRoom()
229  */
230 enum {
231         crr_ok,                         /* success */
232         crr_room_not_found,             /* room not found */
233         crr_already_exists,             /* new name already exists */
234         crr_noneditable,                /* cannot edit this room */
235         crr_invalid_floor,              /* target floor does not exist */
236         crr_access_denied               /* not allowed to edit this room */
237 };
238
239
240
241 /*
242  * API declarations from citserver.h
243  */
244 int CtdlAccessCheck(int);
245 /* 'required access level' values which may be passed to CtdlAccessCheck()
246  */
247 enum {
248         ac_none,
249         ac_logged_in,
250         ac_room_aide,
251         ac_aide,
252         ac_internal
253 };
254
255
256
257 /*
258  * API declarations from serv_extensions.h
259  */
260 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, char *search_string, char *func_name);
261 /* 
262  * Global system configuration.  Don't change anything here.  It's all in dtds/config-defs.h now.
263  */
264 struct config {
265 #include "datadefinitions.h"
266 #include "dtds/config-defs.h"
267 #include "undef_data.h"
268 };
269
270 extern struct config config;
271
272 #endif /* CTDL_MODULE_H */