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