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