Removed the logging facility from citserver, use syslog instead
[citadel.git] / citadel / include / ctdl_module.h
1
2 #ifndef CTDL_MODULE_H
3 #define CTDL_MODULE_H
4
5 #include "sysdep.h"
6
7 #ifdef HAVE_GC
8 #define GC_THREADS
9 #define GC_REDIRECT_TO_LOCAL
10 #include <gc/gc_local_alloc.h>
11 #else
12 #define GC_MALLOC malloc
13 #define GC_MALLOC_ATOMIC malloc
14 #define GC_FREE free
15 #define GC_REALLOC realloc
16 #endif
17
18
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <stdio.h>
22 #include <fcntl.h>
23 #include <ctype.h>
24 #include <signal.h>
25 #include <pwd.h>
26 #include <errno.h>
27 #include <syslog.h>
28 #include <sys/types.h>
29
30 #if TIME_WITH_SYS_TIME
31 # include <sys/time.h>
32 # include <time.h>
33 #else
34 # if HAVE_SYS_TIME_H
35 #  include <sys/time.h>
36 # else
37 #  include <time.h>
38 # endif
39 #endif
40
41 #include <sys/wait.h>
42 #include <string.h>
43 #ifdef HAVE_STRINGS_H
44 #include <strings.h>
45 #endif
46 #include <limits.h>
47
48
49 #ifndef HAVE_SNPRINTF
50 #include "snprintf.h"
51 #endif
52
53
54 #include <libcitadel.h>
55
56 #include "server.h"
57 #include "sysdep_decls.h"
58 #include "msgbase.h"
59 #include "threads.h"
60 #include "citadel_dirs.h"
61 #include "context.h"
62
63 /*
64  * define macros for module init stuff
65  */
66  
67 #define CTDL_MODULE_INIT(module_name) char *ctdl_module_##module_name##_init (int threading)
68
69 #define CTDL_INIT_CALL(module_name) ctdl_module_##module_name##_init (threading)
70
71 #define CTDL_MODULE_UPGRADE(module_name) char *ctdl_module_##module_name##_upgrade (void)
72
73 #define CTDL_UPGRADE_CALL(module_name) ctdl_module_##module_name##_upgrade ()
74
75 #define CtdlAideMessage(TEXT, SUBJECT) quickie_message("Citadel",NULL,NULL,AIDEROOM,TEXT,FMT_CITADEL,SUBJECT) 
76 /*
77  * Hook functions available to modules.
78  */
79
80 void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType);
81 void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
82 void CtdlShutdownServiceHooks(void);
83
84 void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
85 void CtdlUnregisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
86
87 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
88 void CtdlUnregisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
89
90 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
91                                                         int EventType);
92 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
93                                                         int EventType);
94
95 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
96 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
97
98 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
99 void CtdlUnregisterRoomHook(int (*fnc_ptr)(struct ctdlroom *) );
100
101 void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
102 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) );
103
104 void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
105 void CtdlUnregisterCleanupHook(void (*fcn_ptr)(void));
106
107 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
108
109 void CtdlRegisterServiceHook(int tcp_port,
110                              char *sockpath,
111                              void (*h_greeting_function) (void),
112                              void (*h_command_function) (void),
113                              void (*h_async_function) (void),
114                              const char *ServiceName
115 );
116 void CtdlUnregisterServiceHook(int tcp_port,
117                         char *sockpath,
118                         void (*h_greeting_function) (void),
119                         void (*h_command_function) (void),
120                         void (*h_async_function) (void)
121 );
122
123 void CtdlRegisterFixedOutputHook(char *content_type,
124                         void (*output_function) (char *supplied_data, int len)
125 );
126 void CtdlUnRegisterFixedOutputHook(char *content_type);
127
128 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
129
130 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name);
131
132
133 /*
134  * Directory services hooks for LDAP etc
135  */
136
137 #define DIRECTORY_USER_DEL 1    // Delete a user entry
138 #define DIRECTORY_CREATE_HOST 2 // Create a host entry if not already there.
139 #define DIRECTORY_CREATE_OBJECT 3       // Create a new object for directory entry
140 #define DIRECTORY_ATTRIB_ADD 4  // Add an attribute to the directory entry object
141 #define DIRECTORY_SAVE_OBJECT 5 // Save the object to the directory service
142 #define DIRECTORY_FREE_OBJECT 6 // Free the object and its attributes
143
144 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module);
145 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd);
146
147 /* TODODRW: This needs to be changed into a hook type interface
148  * for now we have this horrible hack
149  */
150 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
151
152
153 /*
154  * Citadel Threads API
155  */
156 struct CtdlThreadNode *CtdlThreadCreate(char *name, long flags, void *(*thread_func) (void *arg), void *args);
157 void CtdlThreadSleep(int secs);
158 void CtdlThreadStop(struct CtdlThreadNode *thread);
159 int CtdlThreadCheckStop(void);
160 /* void CtdlThreadCancel2(struct CtdlThreadNode *thread); Leave this out, it should never be needed */
161 const char *CtdlThreadName(const char *name);
162 struct CtdlThreadNode *CtdlThreadSelf(void);
163 int CtdlThreadGetCount(void);
164 int CtdlThreadGetWorkers(void);
165 double CtdlThreadGetWorkerAvg(void);
166 double CtdlThreadGetLoadAvg(void);
167 void CtdlThreadGC(void);
168 void CtdlThreadStopAll(void);
169 int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
170 void CtdlThreadAllocTSD(void);
171
172 #define CTDLTHREAD_BIGSTACK     0x0001
173 #define CTDLTHREAD_WORKER       0x0002
174
175 /* Macros to speed up getting outr thread */
176
177 #define MYCURSORS       (((ThreadTSD*)pthread_getspecific(ThreadKey))->cursors)
178 #define MYTID           (((ThreadTSD*)pthread_getspecific(ThreadKey))->tid)
179 #define CT              (((ThreadTSD*)pthread_getspecific(ThreadKey))->self)
180 #define CTP             ((ThreadTSD*)pthread_getspecific(ThreadKey))
181
182 /** return the current context list as an array and do it in a safe manner
183  * The returned data is a copy so only reading is useful
184  * The number of contexts is returned in count.
185  * Beware, this does not copy any of the data pointed to by the context.
186  * This means that you can not rely on things like the redirect buffer being valid.
187  * You must free the returned pointer when done.
188  */
189 struct CitContext *CtdlGetContextArray (int *count);
190 void CtdlFillSystemContext(struct CitContext *context, char *name);
191 void CtdlClearSystemContext(void);
192 int CtdlTrySingleUser(void);
193 void CtdlEndSingleUser(void);
194 int CtdlWantSingleUser(void);
195 int CtdlIsSingleUser(void);
196
197
198 int CtdlIsUserLoggedIn (char *user_name);
199 int CtdlIsUserLoggedInByNum (long usernum);
200 void CtdlBumpNewMailCounter(long which_user);
201
202
203 /*
204  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
205  * This provides a quick way to initialise a variable that might be used to indicate
206  * messages that should not be processed. EG. a new Sieve script will use this
207  * to record determine that messages older than this should not be processed.
208  * This function is defined in control.c
209  */
210 long CtdlGetCurrentMessageNumber(void);
211
212
213
214 /*
215  * Expose various room operation functions from room_ops.c to the modules API
216  */
217
218 unsigned CtdlCreateRoom(char *new_room_name,
219                         int new_room_type,
220                         char *new_room_pass,
221                         int new_room_floor,
222                         int really_create,
223                         int avoid_access,
224                         int new_room_view);
225 int CtdlGetRoom(struct ctdlroom *qrbuf, char *room_name);
226 int CtdlGetRoomLock(struct ctdlroom *qrbuf, char *room_name);
227 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr);
228 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
229                 int *result, int *view);
230 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
231 void CtdlForEachRoom(void (*CallBack)(struct ctdlroom *EachRoom, void *out_data),
232         void *in_data);
233 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
234 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
235 void CtdlUserGoto (char *where, int display_result, int transiently,
236                         int *msgs, int *new);
237 struct floor *CtdlGetCachedFloor(int floor_num);
238 void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf);
239 void CtdlGetFloor (struct floor *flbuf, int floor_num);
240 void CtdlPutFloor (struct floor *flbuf, int floor_num);
241 void CtdlPutFloorLock(struct floor *flbuf, int floor_num);
242 int CtdlGetFloorByName(const char *floor_name);
243 int CtdlGetFloorByNameLock(const char *floor_name);
244 int CtdlGetAvailableFloor(void);
245 int CtdlIsNonEditable(struct ctdlroom *qrbuf);
246 void CtdlPutRoom(struct ctdlroom *);
247
248 /*
249  * Possible return values for CtdlRenameRoom()
250  */
251 enum {
252         crr_ok,                         /* success */
253         crr_room_not_found,             /* room not found */
254         crr_already_exists,             /* new name already exists */
255         crr_noneditable,                /* cannot edit this room */
256         crr_invalid_floor,              /* target floor does not exist */
257         crr_access_denied               /* not allowed to edit this room */
258 };
259
260
261
262 /*
263  * API declarations from citserver.h
264  */
265 int CtdlAccessCheck(int);
266 /* 'required access level' values which may be passed to CtdlAccessCheck()
267  */
268 enum {
269         ac_none,
270         ac_logged_in_or_guest,
271         ac_logged_in,
272         ac_room_aide,
273         ac_aide,
274         ac_internal,
275 };
276
277
278
279 /*
280  * API declarations from serv_extensions.h
281  */
282 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name);
283 /* 
284  * Global system configuration.  Don't change anything here.  It's all in dtds/config-defs.h now.
285  */
286 struct config {
287 #include "datadefinitions.h"
288 #include "dtds/config-defs.h"
289 #include "undef_data.h"
290 };
291
292 extern struct config config;
293
294
295
296 /*
297  * Expose API calls from user_ops.c
298  */
299 int CtdlGetUser(struct ctdluser *usbuf, char *name);
300 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len);
301 int CtdlGetUserLock(struct ctdluser *usbuf, char *name);
302 void CtdlPutUser(struct ctdluser *usbuf);
303 void CtdlPutUserLock(struct ctdluser *usbuf);
304 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number);
305 void CtdlGetRelationship(visit *vbuf,
306                         struct ctdluser *rel_user,
307                         struct ctdlroom *rel_room);
308 void CtdlSetRelationship(visit *newvisit,
309                         struct ctdluser *rel_user,
310                         struct ctdlroom *rel_room);
311 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix);
312
313 int CtdlLoginExistingUser(char *authname, const char *username);
314
315 /*
316  * Values which may be returned by CtdlLoginExistingUser()
317  */
318 enum {
319         pass_ok,
320         pass_already_logged_in,
321         pass_no_user,
322         pass_internal_error,
323         pass_wrong_password
324 };
325
326 int CtdlTryPassword(const char *password, long len);
327 /*
328  * Values which may be returned by CtdlTryPassword()
329  */
330 enum {
331         login_ok,
332         login_already_logged_in,
333         login_too_many_users,
334         login_not_found
335 };
336
337 void CtdlUserLogout(void);
338
339
340
341
342 /*
343  * Expose API calls from msgbase.c
344  */
345 char *CtdlGetSysConfig(char *sysconfname);
346 void CtdlPutSysConfig(char *sysconfname, char *sysconfdata);
347
348
349
350
351 /*
352  * Expose API calls from euidindex.c
353  */
354 long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf);
355
356
357 #endif /* CTDL_MODULE_H */