citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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