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)  

Loading...
Searching...
No Matches
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
46extern 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
101void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType, int Priority);
102void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
103void CtdlShutdownServiceHooks(void);
104
105void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
106void CtdlUnregisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
107
108void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
109void CtdlUnregisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
110
111void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType);
112void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType);
113
114void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
115void CtdlUnregisterRoomHook(int (*fnc_ptr)(struct ctdlroom *) );
116
117void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
118void CtdlUnregisterDeleteHook(void (*handler)(char *, long) );
119
120void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
121void CtdlUnregisterCleanupHook(void (*fcn_ptr)(void));
122
123void CtdlRegisterEVCleanupHook(void (*fcn_ptr)(void));
124void CtdlUnregisterEVCleanupHook(void (*fcn_ptr)(void));
125
126void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
127
128void 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);
135void 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
142void CtdlRegisterFixedOutputHook(char *content_type, void (*output_function) (char *supplied_data, int len));
143void CtdlUnRegisterFixedOutputHook(char *content_type);
144void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
145void 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 */
151void CtdlDisableHouseKeeping(void);
152void CtdlEnableHouseKeeping(void);
153
154/* TODODRW: This needs to be changed into a hook type interface
155 * for now we have this horrible hack
156 */
157void 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 */
166struct CitContext *CtdlGetContextArray (int *count);
167void CtdlFillSystemContext(struct CitContext *context, char *name);
168int CtdlTrySingleUser(void);
169void CtdlEndSingleUser(void);
170int CtdlWantSingleUser(void);
171int CtdlIsSingleUser(void);
172
173
174int CtdlIsUserLoggedIn (char *user_name);
175int CtdlIsUserLoggedInByNum (long usernum);
176void 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 */
187
188
189
190/*
191 * Expose various room operation functions from room_ops.c to the modules API
192 */
193
194unsigned 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);
201int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name);
202int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name);
204void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *result, int *view);
205void CtdlPutRoomLock(struct ctdlroom *qrbuf);
206typedef void (*ForEachRoomCallBack)(struct ctdlroom *EachRoom, void *out_data);
207void CtdlForEachRoom(ForEachRoomCallBack CB, void *in_data);
208char *LoadRoomNetConfigFile(long roomnum);
209void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig);
210void CtdlDeleteRoom(struct ctdlroom *qrbuf);
211int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
212void CtdlUserGoto (char *where, int display_result, int transiently, int *msgs, int *new, long *oldest, long *newest);
213struct floor *CtdlGetCachedFloor(int floor_num);
215void CtdlGetFloor (struct floor *flbuf, int floor_num);
216void CtdlPutFloor (struct floor *flbuf, int floor_num);
217void CtdlPutFloorLock(struct floor *flbuf, int floor_num);
218int CtdlGetFloorByName(const char *floor_name);
219int CtdlGetFloorByNameLock(const char *floor_name);
220int CtdlGetAvailableFloor(void);
221int CtdlIsNonEditable(struct ctdlroom *qrbuf);
222void CtdlPutRoom(struct ctdlroom *);
223
224/*
225 * Possible return values for CtdlRenameRoom()
226 */
227enum {
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 */
235
236
237
238/*
239 * API declarations from citserver.h
240 */
241int CtdlAccessCheck(int);
242/* 'required access level' values which may be passed to CtdlAccessCheck()
243 */
244enum {
251};
252
253
254
255/*
256 * API declarations from serv_extensions.h
257 */
258void 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 */
276int CtdlGetUser(struct ctdluser *usbuf, char *name);
277int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len);
278int CtdlGetUserLock(struct ctdluser *usbuf, char *name);
279void CtdlPutUser(struct ctdluser *usbuf);
280void CtdlPutUserLock(struct ctdluser *usbuf);
281int CtdlLockGetCurrentUser(void);
282void CtdlPutCurrentUserLock(void);
283int CtdlGetUserByNumber(struct ctdluser *usbuf, long number);
284void CtdlGetRelationship(visit *vbuf, struct ctdluser *rel_user, struct ctdlroom *rel_room);
285void CtdlSetRelationship(visit *newvisit, struct ctdluser *rel_user, struct ctdlroom *rel_room);
286void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix);
287int CtdlLoginExistingUser(const char *username);
288
289/*
290 * Values which may be returned by CtdlLoginExistingUser()
291 */
292enum {
299
300int CtdlTryPassword(const char *password, long len);
301/*
302 * Values which may be returned by CtdlTryPassword()
303 */
304enum {
310
311void CtdlUserLogout(void);
312
313/*
314 * Expose API calls from msgbase.c
315 */
316
317
318/*
319 * Expose API calls from euidindex.c
320 */
321long 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 */
327int attach_extauth(struct ctdluser *who, StrBuf *claimed_id);
328
329#endif /* CTDL_MODULE_H */
int CtdlAccessCheck(int)
Definition: user_ops.c:334
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:277
void CtdlPutUser(struct ctdluser *usbuf)
Definition: user_ops.c:107
void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
@ crr_invalid_floor
Definition: ctdl_module.h:232
@ crr_noneditable
Definition: ctdl_module.h:231
@ crr_room_not_found
Definition: ctdl_module.h:229
@ crr_ok
Definition: ctdl_module.h:228
@ crr_already_exists
Definition: ctdl_module.h:230
@ crr_access_denied
Definition: ctdl_module.h:233
void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
Definition: user_ops.c:305
int CtdlLockGetCurrentUser(void)
Definition: user_ops.c:89
void CtdlGetFloor(struct floor *flbuf, int floor_num)
Definition: room_ops.c:450
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:36
int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name)
Definition: room_ops.c:309
int CtdlIsUserLoggedInByNum(long usernum)
Definition: context.c:165
long CtdlGetCurrentMessageNumber(void)
Definition: control.c:198
int CtdlGetUserByNumber(struct ctdluser *usbuf, long number)
Definition: user_ops.c:398
void CtdlUnregisterDeleteHook(void(*handler)(char *, long))
int CtdlWantSingleUser(void)
Definition: context.c:54
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:408
void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf)
Definition: room_ops.c:942
long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf)
Definition: euidindex.c:52
int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len)
char * LoadRoomNetConfigFile(long roomnum)
Definition: netconfig.c:61
void CtdlDisableHouseKeeping(void)
Definition: housekeeping.c:150
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:115
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:661
int CtdlGetUserLock(struct ctdluser *usbuf, char *name)
Definition: user_ops.c:95
void CtdlRegisterMessageHook(int(*handler)(struct CtdlMessage *, struct recptypes *), int EventType)
int threading
Definition: modules_init.c:24
void CtdlDeleteRoom(struct ctdlroom *qrbuf)
Definition: room_ops.c:970
void CtdlEnableHouseKeeping(void)
Definition: housekeeping.c:169
int CtdlGetAvailableFloor(void)
Definition: room_ops.c:433
void CtdlFillSystemContext(struct CitContext *context, char *name)
Definition: context.c:531
void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *result, int *view)
Definition: room_ops.c:103
struct floor * CtdlGetCachedFloor(int floor_num)
Definition: room_ops.c:478
void CtdlBumpNewMailCounter(long which_user)
Definition: context.c:121
int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name)
Definition: room_ops.c:352
void CtdlUnregisterXmsgHook(int(*fcn_ptr)(char *, char *, char *, char *), int order)
void CtdlPutRoom(struct ctdlroom *)
Definition: room_ops.c:388
@ pass_internal_error
Definition: ctdl_module.h:296
@ pass_ok
Definition: ctdl_module.h:293
@ pass_no_user
Definition: ctdl_module.h:295
@ pass_already_logged_in
Definition: ctdl_module.h:294
@ pass_wrong_password
Definition: ctdl_module.h:297
int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr)
Definition: room_ops.c:1000
int CtdlTrySingleUser(void)
Definition: context.c:31
void CtdlUnregisterSessionHook(void(*fcn_ptr)(void), int EventType)
int CtdlTryPassword(const char *password, long len)
Definition: user_ops.c:772
void CtdlForEachRoom(ForEachRoomCallBack CB, void *in_data)
Definition: room_ops.c:542
void CtdlUnregisterCleanupHook(void(*fcn_ptr)(void))
int CtdlGetFloorByNameLock(const char *floor_name)
Definition: room_ops.c:425
void CtdlPutUserLock(struct ctdluser *usbuf)
Definition: user_ops.c:121
@ login_too_many_users
Definition: ctdl_module.h:307
@ login_not_found
Definition: ctdl_module.h:308
@ login_ok
Definition: ctdl_module.h:305
@ login_already_logged_in
Definition: ctdl_module.h:306
int CtdlIsUserLoggedIn(char *user_name)
Definition: context.c:142
void(* ForEachRoomCallBack)(struct ctdlroom *EachRoom, void *out_data)
Definition: ctdl_module.h:206
void CtdlPutFloor(struct floor *flbuf, int floor_num)
Definition: room_ops.c:512
void CtdlSetRelationship(visit *newvisit, struct ctdluser *rel_user, struct ctdlroom *rel_room)
Definition: user_ops.c:265
void CtdlRegisterEVCleanupHook(void(*fcn_ptr)(void))
struct CitContext * CtdlGetContextArray(int *count)
Definition: context.c:423
int CtdlLoginExistingUser(const char *username)
Definition: user_ops.c:461
void CtdlEndSingleUser(void)
Definition: context.c:47
int CtdlIsSingleUser(void)
Definition: context.c:59
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:829
@ ac_room_aide
Definition: ctdl_module.h:248
@ ac_none
Definition: ctdl_module.h:245
@ ac_logged_in_or_guest
Definition: ctdl_module.h:246
@ ac_aide
Definition: ctdl_module.h:249
@ ac_logged_in
Definition: ctdl_module.h:247
@ ac_internal
Definition: ctdl_module.h:250
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:1035
int CtdlIsNonEditable(struct ctdlroom *qrbuf)
Definition: room_ops.c:608
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:623
void CtdlRegisterDeleteHook(void(*handler)(char *, long))
int CtdlGetUser(struct ctdluser *usbuf, char *name)
Definition: user_ops.c:64
void CtdlPutRoomLock(struct ctdlroom *qrbuf)
Definition: room_ops.c:400
void CtdlRegisterUserHook(void(*fcn_ptr)(struct ctdluser *), int EventType)
void CtdlPutFloorLock(struct floor *flbuf, int floor_num)
Definition: room_ops.c:528
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:124