This is an omnibus commit which moves the Citadel Server from crusty old GNU Autotool...
[citadel.git] / citadel / server / 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 #include <time.h>
30 #include <sys/wait.h>
31 #include <string.h>
32 #ifdef HAVE_STRINGS_H
33 #include <strings.h>
34 #endif
35 #include <limits.h>
36
37 #include <libcitadel.h>
38
39 #include "server.h"
40 #include "sysdep_decls.h"
41 #include "msgbase.h"
42 #include "threads.h"
43 #include "citadel_dirs.h"
44 #include "context.h"
45
46 extern int threading;
47
48
49 /*
50  * define macros for module init stuff
51  */
52  
53 #define CTDL_MODULE_INIT(module_name) char *ctdl_module_##module_name##_init (int threading)
54
55 #define CTDL_INIT_CALL(module_name) ctdl_module_##module_name##_init (threading)
56
57 #define CTDL_MODULE_UPGRADE(module_name) char *ctdl_module_##module_name##_upgrade (void)
58
59 #define CTDL_UPGRADE_CALL(module_name) ctdl_module_##module_name##_upgrade ()
60
61 #define CtdlAideMessage(TEXT, SUBJECT)          \
62         quickie_message(                        \
63                 "Citadel",                      \
64                 NULL,                           \
65                 NULL,                           \
66                 AIDEROOM,                       \
67                 TEXT,                           \
68                 FMT_CITADEL,                    \
69                 SUBJECT) 
70
71 /*
72  * Hook functions available to modules.
73  */
74 /* Priorities for  */
75 #define PRIO_QUEUE 500
76 #define PRIO_AGGR 1000
77 #define PRIO_SEND 1500
78 #define PRIO_CLEANUP 2000
79 /* Priorities for EVT_HOUSE */
80 #define PRIO_HOUSE 3000
81 /* Priorities for EVT_LOGIN */
82 #define PRIO_CREATE 10000
83 /* Priorities for EVT_LOGOUT */
84 #define PRIO_LOGOUT 15000
85 /* Priorities for EVT_LOGIN */
86 #define PRIO_LOGIN 20000
87 /* Priorities for EVT_START */
88 #define PRIO_START 25000
89 /* Priorities for EVT_STOP */
90 #define PRIO_STOP 30000
91 /* Priorities for EVT_ASYNC */
92 #define PRIO_ASYNC 35000
93 /* Priorities for EVT_SHUTDOWN */
94 #define PRIO_SHUTDOWN 40000
95 /* Priorities for EVT_UNSTEALTH */
96 #define PRIO_UNSTEALTH 45000
97 /* Priorities for EVT_STEALTH */
98 #define PRIO_STEALTH 50000
99
100
101 void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType, int Priority);
102 void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
103 void CtdlShutdownServiceHooks(void);
104
105 void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
106 void CtdlUnregisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
107
108 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
109 void CtdlUnregisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
110
111 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType);
112 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType);
113
114 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
115 void CtdlUnregisterRoomHook(int (*fnc_ptr)(struct ctdlroom *) );
116
117 void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
118 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) );
119
120 void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
121 void CtdlUnregisterCleanupHook(void (*fcn_ptr)(void));
122
123 void CtdlRegisterEVCleanupHook(void (*fcn_ptr)(void));
124 void CtdlUnregisterEVCleanupHook(void (*fcn_ptr)(void));
125
126 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
127
128 void CtdlRegisterServiceHook(int tcp_port,
129                              char *sockpath,
130                              void (*h_greeting_function) (void),
131                              void (*h_command_function) (void),
132                              void (*h_async_function) (void),
133                              const char *ServiceName
134 );
135 void CtdlUnregisterServiceHook(int tcp_port,
136                         char *sockpath,
137                         void (*h_greeting_function) (void),
138                         void (*h_command_function) (void),
139                         void (*h_async_function) (void)
140 );
141
142 void CtdlRegisterFixedOutputHook(char *content_type, void (*output_function) (char *supplied_data, int len));
143 void CtdlUnRegisterFixedOutputHook(char *content_type);
144 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
145 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, const char *), char *name);
146
147 /*
148  * if you say a) (which may take a while)
149  * don't forget to say b)
150  */
151 void CtdlDisableHouseKeeping(void);
152 void CtdlEnableHouseKeeping(void);
153
154 /* TODODRW: This needs to be changed into a hook type interface
155  * for now we have this horrible hack
156  */
157 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
158
159 /* return the current context list as an array and do it in a safe manner
160  * The returned data is a copy so only reading is useful
161  * The number of contexts is returned in count.
162  * Beware, this does not copy any of the data pointed to by the context.
163  * This means that you can not rely on things like the redirect buffer being valid.
164  * You must free the returned pointer when done.
165  */
166 struct CitContext *CtdlGetContextArray (int *count);
167 void CtdlFillSystemContext(struct CitContext *context, char *name);
168 int CtdlTrySingleUser(void);
169 void CtdlEndSingleUser(void);
170 int CtdlWantSingleUser(void);
171 int CtdlIsSingleUser(void);
172
173
174 int CtdlIsUserLoggedIn (char *user_name);
175 int CtdlIsUserLoggedInByNum (long usernum);
176 void CtdlBumpNewMailCounter(long which_user);
177
178
179 /*
180  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
181  * This provides a quick way to initialize a variable that might be used to indicate
182  * messages that should not be processed.  For example, a new inbox script will use this
183  * to record determine that messages older than this should not be processed.
184  * This function is defined in control.c
185  */
186 long CtdlGetCurrentMessageNumber(void);
187
188
189
190 /*
191  * Expose various room operation functions from room_ops.c to the modules API
192  */
193
194 unsigned CtdlCreateRoom(char *new_room_name,
195                         int new_room_type,
196                         char *new_room_pass,
197                         int new_room_floor,
198                         int really_create,
199                         int avoid_access,
200                         int new_room_view);
201 int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name);
202 int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name);
203 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr);
204 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *result, int *view);
205 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
206 typedef void (*ForEachRoomCallBack)(struct ctdlroom *EachRoom, void *out_data);
207 void CtdlForEachRoom(ForEachRoomCallBack CB, void *in_data);
208 char *LoadRoomNetConfigFile(long roomnum);
209 void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig);
210 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
211 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
212 void CtdlUserGoto (char *where, int display_result, int transiently, int *msgs, int *new, long *oldest, long *newest);
213 struct floor *CtdlGetCachedFloor(int floor_num);
214 void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf);
215 void CtdlGetFloor (struct floor *flbuf, int floor_num);
216 void CtdlPutFloor (struct floor *flbuf, int floor_num);
217 void CtdlPutFloorLock(struct floor *flbuf, int floor_num);
218 int CtdlGetFloorByName(const char *floor_name);
219 int CtdlGetFloorByNameLock(const char *floor_name);
220 int CtdlGetAvailableFloor(void);
221 int CtdlIsNonEditable(struct ctdlroom *qrbuf);
222 void CtdlPutRoom(struct ctdlroom *);
223
224 /*
225  * Possible return values for CtdlRenameRoom()
226  */
227 enum {
228         crr_ok,                         /* success */
229         crr_room_not_found,             /* room not found */
230         crr_already_exists,             /* new name already exists */
231         crr_noneditable,                /* cannot edit this room */
232         crr_invalid_floor,              /* target floor does not exist */
233         crr_access_denied               /* not allowed to edit this room */
234 };
235
236
237
238 /*
239  * API declarations from citserver.h
240  */
241 int CtdlAccessCheck(int);
242 /* 'required access level' values which may be passed to CtdlAccessCheck()
243  */
244 enum {
245         ac_none,
246         ac_logged_in_or_guest,
247         ac_logged_in,
248         ac_room_aide,
249         ac_aide,
250         ac_internal,
251 };
252
253
254
255 /*
256  * API declarations from serv_extensions.h
257  */
258 void CtdlModuleDoSearch(int *num_msgs, long **search_msgs, const char *search_string, const char *func_name);
259
260 #define NODENAME                CtdlGetConfigStr("c_nodename")
261 #define FQDN                    CtdlGetConfigStr("c_fqdn")
262 #define CTDLUID                 ctdluid
263 #define CREATAIDE               CtdlGetConfigInt("c_creataide")
264 #define REGISCALL               CtdlGetConfigInt("c_regiscall")
265 #define TWITDETECT              CtdlGetConfigInt("c_twitdetect")
266 #define TWITROOM                CtdlGetConfigStr("c_twitroom")
267 #define RESTRICT_INTERNET       CtdlGetConfigInt("c_restrict")
268
269 #define CtdlREGISTERRoomCfgType(a, p, uniq, nSegs, s, d) RegisterRoomCfgType(#a, sizeof(#a) - 1, a, p, uniq, nSegs, s, d);
270
271
272
273 /*
274  * Expose API calls from user_ops.c
275  */
276 int CtdlGetUser(struct ctdluser *usbuf, char *name);
277 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len);
278 int CtdlGetUserLock(struct ctdluser *usbuf, char *name);
279 void CtdlPutUser(struct ctdluser *usbuf);
280 void CtdlPutUserLock(struct ctdluser *usbuf);
281 int CtdlLockGetCurrentUser(void);
282 void CtdlPutCurrentUserLock(void);
283 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number);
284 void CtdlGetRelationship(visit *vbuf, struct ctdluser *rel_user, struct ctdlroom *rel_room);
285 void CtdlSetRelationship(visit *newvisit, struct ctdluser *rel_user, struct ctdlroom *rel_room);
286 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix);
287 int CtdlLoginExistingUser(const char *username);
288
289 /*
290  * Values which may be returned by CtdlLoginExistingUser()
291  */
292 enum {
293         pass_ok,
294         pass_already_logged_in,
295         pass_no_user,
296         pass_internal_error,
297         pass_wrong_password
298 };
299
300 int CtdlTryPassword(const char *password, long len);
301 /*
302  * Values which may be returned by CtdlTryPassword()
303  */
304 enum {
305         login_ok,
306         login_already_logged_in,
307         login_too_many_users,
308         login_not_found
309 };
310
311 void CtdlUserLogout(void);
312
313 /*
314  * Expose API calls from msgbase.c
315  */
316
317
318 /*
319  * Expose API calls from euidindex.c
320  */
321 long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf);
322
323
324 /*
325  * Expose API calls from modules/openid/serv_openid_rp.c in order to turn it into a generic external authentication driver
326  */
327 int attach_extauth(struct ctdluser *who, StrBuf *claimed_id);
328
329 #endif /* CTDL_MODULE_H */