e3ec8098bf3f0e4ca2c01db221fdc198b33ca99c
[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 CtdlShutdownServiceHooks(void);
103 void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
104 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
105 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType);
106 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
107 void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
108 void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
109 void CtdlRegisterEVCleanupHook(void (*fcn_ptr)(void));
110 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
111 void CtdlRegisterServiceHook(int tcp_port,
112                              char *sockpath,
113                              void (*h_greeting_function) (void),
114                              void (*h_command_function) (void),
115                              void (*h_async_function) (void),
116                              const char *ServiceName
117 );
118 void CtdlRegisterFixedOutputHook(char *content_type, void (*output_function) (char *supplied_data, int len));
119 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
120
121 /*
122  * if you say a) (which may take a while)
123  * don't forget to say b)
124  */
125 void CtdlDisableHouseKeeping(void);
126 void CtdlEnableHouseKeeping(void);
127
128 /* TODODRW: This needs to be changed into a hook type interface
129  * for now we have this horrible hack
130  */
131 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
132
133 /* return the current context list as an array and do it in a safe manner
134  * The returned data is a copy so only reading is useful
135  * The number of contexts is returned in count.
136  * Beware, this does not copy any of the data pointed to by the context.
137  * This means that you can not rely on things like the redirect buffer being valid.
138  * You must free the returned pointer when done.
139  */
140 struct CitContext *CtdlGetContextArray (int *count);
141 void CtdlFillSystemContext(struct CitContext *context, char *name);
142 int CtdlTrySingleUser(void);
143 void CtdlEndSingleUser(void);
144 int CtdlWantSingleUser(void);
145 int CtdlIsSingleUser(void);
146
147
148 int CtdlIsUserLoggedIn (char *user_name);
149 int CtdlIsUserLoggedInByNum (long usernum);
150 void CtdlBumpNewMailCounter(long which_user);
151
152
153 /*
154  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
155  * This provides a quick way to initialize a variable that might be used to indicate
156  * messages that should not be processed.  For example, a new inbox script will use this
157  * to record determine that messages older than this should not be processed.
158  * This function is defined in control.c
159  */
160 long CtdlGetCurrentMessageNumber(void);
161
162
163
164 /*
165  * Expose various room operation functions from room_ops.c to the modules API
166  */
167
168 unsigned CtdlCreateRoom(char *new_room_name,
169                         int new_room_type,
170                         char *new_room_pass,
171                         int new_room_floor,
172                         int really_create,
173                         int avoid_access,
174                         int new_room_view);
175 int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name);
176 int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name);
177 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr);
178 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *result, int *view);
179 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
180 typedef void (*ForEachRoomCallBack)(struct ctdlroom *EachRoom, void *out_data);
181 void CtdlForEachRoom(ForEachRoomCallBack CB, void *in_data);
182 char *LoadRoomNetConfigFile(long roomnum);
183 void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig);
184 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
185 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
186 void CtdlUserGoto (char *where, int display_result, int transiently, int *msgs, int *new, long *oldest, long *newest);
187 struct floor *CtdlGetCachedFloor(int floor_num);
188 void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf);
189 void CtdlGetFloor (struct floor *flbuf, int floor_num);
190 void CtdlPutFloor (struct floor *flbuf, int floor_num);
191 void CtdlPutFloorLock(struct floor *flbuf, int floor_num);
192 int CtdlGetFloorByName(const char *floor_name);
193 int CtdlGetFloorByNameLock(const char *floor_name);
194 int CtdlGetAvailableFloor(void);
195 int CtdlIsNonEditable(struct ctdlroom *qrbuf);
196 void CtdlPutRoom(struct ctdlroom *);
197
198 /*
199  * Possible return values for CtdlRenameRoom()
200  */
201 enum {
202         crr_ok,                         /* success */
203         crr_room_not_found,             /* room not found */
204         crr_already_exists,             /* new name already exists */
205         crr_noneditable,                /* cannot edit this room */
206         crr_invalid_floor,              /* target floor does not exist */
207         crr_access_denied               /* not allowed to edit this room */
208 };
209
210
211
212 /*
213  * API declarations from citserver.h
214  */
215 int CtdlAccessCheck(int);
216 /* 'required access level' values which may be passed to CtdlAccessCheck()
217  */
218 enum {
219         ac_none,
220         ac_logged_in_or_guest,
221         ac_logged_in,
222         ac_room_aide,
223         ac_aide,
224         ac_internal,
225 };
226
227 #define NODENAME                CtdlGetConfigStr("c_nodename")
228 #define FQDN                    CtdlGetConfigStr("c_fqdn")
229 #define CREATAIDE               CtdlGetConfigInt("c_creataide")
230 #define REGISCALL               CtdlGetConfigInt("c_regiscall")
231 #define TWITDETECT              CtdlGetConfigInt("c_twitdetect")
232 #define TWITROOM                CtdlGetConfigStr("c_twitroom")
233 #define RESTRICT_INTERNET       CtdlGetConfigInt("c_restrict")
234
235 #define CtdlREGISTERRoomCfgType(a, p, uniq, nSegs, s, d) RegisterRoomCfgType(#a, sizeof(#a) - 1, a, p, uniq, nSegs, s, d);
236
237
238
239 /*
240  * Expose API calls from user_ops.c
241  */
242 int CtdlGetUser(struct ctdluser *usbuf, char *name);
243 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len);
244 int CtdlGetUserLock(struct ctdluser *usbuf, char *name);
245 void CtdlPutUser(struct ctdluser *usbuf);
246 void CtdlPutUserLock(struct ctdluser *usbuf);
247 int CtdlLockGetCurrentUser(void);
248 void CtdlPutCurrentUserLock(void);
249 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number);
250 void CtdlGetRelationship(struct visit *vbuf, struct ctdluser *rel_user, struct ctdlroom *rel_room);
251 void CtdlSetRelationship(struct visit *newvisit, struct ctdluser *rel_user, struct ctdlroom *rel_room);
252 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix);
253 int CtdlLoginExistingUser(const char *username);
254
255 /*
256  * Values which may be returned by CtdlLoginExistingUser()
257  */
258 enum {
259         pass_ok,
260         pass_already_logged_in,
261         pass_no_user,
262         pass_internal_error,
263         pass_wrong_password
264 };
265
266 int CtdlTryPassword(const char *password, long len);
267 /*
268  * Values which may be returned by CtdlTryPassword()
269  */
270 enum {
271         login_ok,
272         login_already_logged_in,
273         login_too_many_users,
274         login_not_found
275 };
276
277 void CtdlUserLogout(void);
278
279 /*
280  * Expose API calls from msgbase.c
281  */
282
283
284 /*
285  * Expose API calls from euidindex.c
286  */
287 long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf);
288
289
290 /*
291  * Expose API calls from external authentication driver
292  */
293 int attach_extauth(struct ctdluser *who, StrBuf *claimed_id);
294
295 #endif /* CTDL_MODULE_H */