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