Converted struct config back to an ordinary struct in preparation for its eventual...
[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 /* return the current context list as an array and do it in a safe manner
153  * The returned data is a copy so only reading is useful
154  * The number of contexts is returned in count.
155  * Beware, this does not copy any of the data pointed to by the context.
156  * This means that you can not rely on things like the redirect buffer being valid.
157  * You must free the returned pointer when done.
158  */
159 struct CitContext *CtdlGetContextArray (int *count);
160 void CtdlFillSystemContext(struct CitContext *context, char *name);
161 int CtdlTrySingleUser(void);
162 void CtdlEndSingleUser(void);
163 int CtdlWantSingleUser(void);
164 int CtdlIsSingleUser(void);
165
166
167 int CtdlIsUserLoggedIn (char *user_name);
168 int CtdlIsUserLoggedInByNum (long usernum);
169 void CtdlBumpNewMailCounter(long which_user);
170
171
172 /*
173  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
174  * This provides a quick way to initialise a variable that might be used to indicate
175  * messages that should not be processed. EG. a new Sieve script will use this
176  * to record determine that messages older than this should not be processed.
177  * This function is defined in control.c
178  */
179 long CtdlGetCurrentMessageNumber(void);
180
181
182
183 /*
184  * Expose various room operation functions from room_ops.c to the modules API
185  */
186
187 unsigned CtdlCreateRoom(char *new_room_name,
188                         int new_room_type,
189                         char *new_room_pass,
190                         int new_room_floor,
191                         int really_create,
192                         int avoid_access,
193                         int new_room_view);
194 int CtdlGetRoom(struct ctdlroom *qrbuf, char *room_name);
195 int CtdlGetRoomLock(struct ctdlroom *qrbuf, char *room_name);
196 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr);
197 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
198                 int *result, int *view);
199 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
200 void CtdlForEachRoom(void (*CallBack)(struct ctdlroom *EachRoom, void *out_data),
201         void *in_data);
202 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
203 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
204 void CtdlUserGoto (char *where, int display_result, int transiently,
205                         int *msgs, int *new);
206 struct floor *CtdlGetCachedFloor(int floor_num);
207 void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf);
208 void CtdlGetFloor (struct floor *flbuf, int floor_num);
209 void CtdlPutFloor (struct floor *flbuf, int floor_num);
210 void CtdlPutFloorLock(struct floor *flbuf, int floor_num);
211 int CtdlGetFloorByName(const char *floor_name);
212 int CtdlGetFloorByNameLock(const char *floor_name);
213 int CtdlGetAvailableFloor(void);
214 int CtdlIsNonEditable(struct ctdlroom *qrbuf);
215 void CtdlPutRoom(struct ctdlroom *);
216
217 /*
218  * Possible return values for CtdlRenameRoom()
219  */
220 enum {
221         crr_ok,                         /* success */
222         crr_room_not_found,             /* room not found */
223         crr_already_exists,             /* new name already exists */
224         crr_noneditable,                /* cannot edit this room */
225         crr_invalid_floor,              /* target floor does not exist */
226         crr_access_denied               /* not allowed to edit this room */
227 };
228
229
230
231 /*
232  * API declarations from citserver.h
233  */
234 int CtdlAccessCheck(int);
235 /* 'required access level' values which may be passed to CtdlAccessCheck()
236  */
237 enum {
238         ac_none,
239         ac_logged_in_or_guest,
240         ac_logged_in,
241         ac_room_aide,
242         ac_aide,
243         ac_internal,
244 };
245
246
247
248 /*
249  * API declarations from serv_extensions.h
250  */
251 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name);
252
253 /* 
254  * Global system configuration
255  */
256 struct config {
257         char c_nodename[16];            /* short name of this node on a Citadel network */
258         char c_fqdn[64];                /* this site's fully qualified domain name */
259         char c_humannode[21];           /* human-readable site name */
260         char c_phonenum[16];            /* telephone number */
261         uid_t c_ctdluid;                /* uid of posix account under which Citadel will run */
262         char c_creataide;               /* 1 = creating a room auto-grants room aide privileges */
263         int c_sleeping;                 /* watchdog timer (seconds) */
264         char c_initax;                  /* initial access level for new users */
265         char c_regiscall;               /* after c_regiscall logins user will be asked to register */
266         char c_twitdetect;              /* automatically move messages from problem users to trashcan */
267         char c_twitroom[ROOMNAMELEN];   /* name of trashcan */
268         char c_moreprompt[80];          /* paginator prompt */
269         char c_restrict;                /* require per-user permission to send Internet mail */
270         long c_niu_1;
271         char c_site_location[32];       /* geographic location of this Citadel site */
272         char c_sysadm[26];              /* name of system administrator */
273         char c_niu_2[15];
274         int c_niu_3;
275         int c_maxsessions;              /* maximum number of concurrent sessions allowed */
276         char c_ip_addr[20];             /* bind address for listening sockets */
277         int c_port_number;              /* port number for Citadel protocol (usually 504) */
278         int c_niu_4;
279         struct ExpirePolicy c_ep;       /* default expire policy for the entire site */
280         int c_userpurge;                /* user purge time (in days) */
281         int c_roompurge;                /* room purge time (in days) */
282         char c_logpages[ROOMNAMELEN];
283         char c_createax;
284         long c_maxmsglen;
285         int c_min_workers;
286         int c_max_workers;
287         int c_pop3_port;
288         int c_smtp_port;
289         int c_rfc822_strict_from;
290         int c_aide_zap;
291         int c_imap_port;
292         time_t c_net_freq;
293         char c_disable_newu;
294         char c_enable_fulltext;
295         char c_baseroom[ROOMNAMELEN];
296         char c_aideroom[ROOMNAMELEN];
297         int c_purge_hour;
298         struct ExpirePolicy c_mbxep;
299         char c_ldap_host[128];
300         int c_ldap_port;
301         char c_ldap_base_dn[256];
302         char c_ldap_bind_dn[256];
303         char c_ldap_bind_pw[256];
304         int c_msa_port;
305         int c_imaps_port;
306         int c_pop3s_port;
307         int c_smtps_port;
308         char c_auto_cull;
309         char c_instant_expunge;
310         char c_allow_spoofing;
311         char c_journal_email;
312         char c_journal_pubmsgs;
313         char c_journal_dest[128];
314         char c_default_cal_zone[128];
315         int c_pftcpdict_port;
316         int c_managesieve_port;
317         int c_auth_mode;
318         char c_funambol_host[256];
319         int c_funambol_port;
320         char c_funambol_source[256];
321         char c_funambol_auth[256];
322         char c_rbl_at_greeting;
323         char c_master_user[32];
324         char c_master_pass[32];
325         char c_pager_program[256];
326         char c_imap_keep_from;
327         int c_xmpp_c2s_port;
328         int c_xmpp_s2s_port;
329         time_t c_pop3_fetch;
330         time_t c_pop3_fastest;
331         int c_spam_flag_only;
332         int c_guest_logins;
333 };
334
335 extern struct config config;
336
337
338
339 /*
340  * Expose API calls from user_ops.c
341  */
342 int CtdlGetUser(struct ctdluser *usbuf, char *name);
343 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len);
344 int CtdlGetUserLock(struct ctdluser *usbuf, char *name);
345 void CtdlPutUser(struct ctdluser *usbuf);
346 void CtdlPutUserLock(struct ctdluser *usbuf);
347 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number);
348 void CtdlGetRelationship(visit *vbuf,
349                         struct ctdluser *rel_user,
350                         struct ctdlroom *rel_room);
351 void CtdlSetRelationship(visit *newvisit,
352                         struct ctdluser *rel_user,
353                         struct ctdlroom *rel_room);
354 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix);
355
356 int CtdlLoginExistingUser(char *authname, const char *username);
357
358 /*
359  * Values which may be returned by CtdlLoginExistingUser()
360  */
361 enum {
362         pass_ok,
363         pass_already_logged_in,
364         pass_no_user,
365         pass_internal_error,
366         pass_wrong_password
367 };
368
369 int CtdlTryPassword(const char *password, long len);
370 /*
371  * Values which may be returned by CtdlTryPassword()
372  */
373 enum {
374         login_ok,
375         login_already_logged_in,
376         login_too_many_users,
377         login_not_found
378 };
379
380 void CtdlUserLogout(void);
381
382
383
384
385 /*
386  * Expose API calls from msgbase.c
387  */
388 char *CtdlGetSysConfig(char *sysconfname);
389 void CtdlPutSysConfig(char *sysconfname, char *sysconfdata);
390
391
392
393
394 /*
395  * Expose API calls from euidindex.c
396  */
397 long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf);
398
399
400 #endif /* CTDL_MODULE_H */