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// define macros for module init stuff
50
51#define CTDL_MODULE_INIT(module_name) char *ctdl_module_##module_name##_init (int threading)
52
53#define CTDL_INIT_CALL(module_name) ctdl_module_##module_name##_init (threading)
54
55#define CTDL_MODULE_UPGRADE(module_name) char *ctdl_module_##module_name##_upgrade (void)
56
57#define CTDL_UPGRADE_CALL(module_name) ctdl_module_##module_name##_upgrade ()
58
59#define CtdlAideMessage(TEXT, SUBJECT) \
60 quickie_message( \
61 "Citadel", \
62 NULL, \
63 NULL, \
64 AIDEROOM, \
65 TEXT, \
66 FMT_CITADEL, \
67 SUBJECT)
68
69// Hook functions available to modules.
70
71// Priority levels for event hooks
72#define PRIO_QUEUE 500
73#define PRIO_AGGR 1000
74#define PRIO_SEND 1500
75#define PRIO_CLEANUP 2000
76#define PRIO_HOUSE 3000
77#define PRIO_CREATE 10000
78#define PRIO_LOGOUT 15000
79#define PRIO_LOGIN 20000
80#define PRIO_START 25000
81#define PRIO_STOP 30000
82#define PRIO_ASYNC 35000
83#define PRIO_SHUTDOWN 40000
84#define PRIO_UNSTEALTH 45000
85#define PRIO_STEALTH 50000
86
87void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType, int Priority);
89void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
90void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
91void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType);
92void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
93void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
94void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
95void CtdlRegisterEVCleanupHook(void (*fcn_ptr)(void));
96void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
97void CtdlRegisterServiceHook(int tcp_port,
98 char *sockpath,
99 void (*h_greeting_function) (void),
100 void (*h_command_function) (void),
101 void (*h_async_function) (void),
102 const char *ServiceName
103);
104void CtdlRegisterFixedOutputHook(char *content_type, void (*output_function) (char *supplied_data, int len));
105void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
106
107void CtdlDisableHouseKeeping(void); // If you call this, it may take a while...
108void CtdlEnableHouseKeeping(void); // ...so don't forget to call this later.
109
110// TODODRW: This needs to be changed into a hook type interface
111// for now we have this horrible hack
112void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
113
114// return the current context list as an array and do it in a safe manner
115// The returned data is a copy so only reading is useful
116// The number of contexts is returned in count.
117// Beware, this does not copy any of the data pointed to by the context.
118// This means that you can not rely on things like the redirect buffer being valid.
119// You must free the returned pointer when done.
120struct CitContext *CtdlGetContextArray (int *count);
121void CtdlFillSystemContext(struct CitContext *context, char *name);
122int CtdlTrySingleUser(void);
123void CtdlEndSingleUser(void);
124int CtdlWantSingleUser(void);
125int CtdlIsSingleUser(void);
126
127
128int CtdlIsUserLoggedIn (char *user_name);
129int CtdlIsUserLoggedInByNum (long usernum);
130void CtdlBumpNewMailCounter(long which_user);
131
132
133// CtdlGetCurrentMessageNumber() - Obtain the current highest message number in the system
134// This provides a quick way to initialize a variable that might be used to indicate
135// messages that should not be processed. For example, a new inbox script will use this
136// to record determine that messages older than this should not be processed.
137// This function is defined in control.c
139
140
141
142// Expose various room operation functions from room_ops.c to the modules API
143
144unsigned CtdlCreateRoom(char *new_room_name,
145 int new_room_type,
146 char *new_room_pass,
147 int new_room_floor,
148 int really_create,
149 int avoid_access,
150 int new_room_view);
151int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name);
152int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name);
154void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *result, int *view);
155void CtdlPutRoomLock(struct ctdlroom *qrbuf);
156typedef void (*ForEachRoomCallBack)(struct ctdlroom *EachRoom, void *out_data);
157void CtdlForEachRoom(ForEachRoomCallBack CB, void *in_data);
158char *LoadRoomNetConfigFile(long roomnum);
159void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig);
160void CtdlDeleteRoom(struct ctdlroom *qrbuf);
161int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
162void CtdlUserGoto (char *where, int display_result, int transiently, int *msgs, int *new, long *oldest, long *newest);
163struct floor *CtdlGetCachedFloor(int floor_num);
164void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf);
165void CtdlGetFloor (struct floor *flbuf, int floor_num);
166void CtdlPutFloor (struct floor *flbuf, int floor_num);
167void CtdlPutFloorLock(struct floor *flbuf, int floor_num);
168int CtdlGetFloorByName(const char *floor_name);
169int CtdlGetFloorByNameLock(const char *floor_name);
170int CtdlGetAvailableFloor(void);
171int CtdlIsNonEditable(struct ctdlroom *qrbuf);
172void CtdlPutRoom(struct ctdlroom *);
173
174// Possible return values for CtdlRenameRoom()
175enum {
176 crr_ok, // success
177 crr_room_not_found, // room not found
178 crr_already_exists, // new name already exists
179 crr_noneditable, // cannot edit this room
180 crr_invalid_floor, // target floor does not exist
181 crr_access_denied // not allowed to edit this room
183
184
185
186// API declarations from citserver.h
187int CtdlAccessCheck(int);
188
189// 'required access level' values which may be passed to CtdlAccessCheck()
190enum {
197};
198
199#define NODENAME CtdlGetConfigStr("c_nodename")
200#define FQDN CtdlGetConfigStr("c_fqdn")
201#define CREATAIDE CtdlGetConfigInt("c_creataide")
202#define REGISCALL CtdlGetConfigInt("c_regiscall")
203#define TWITDETECT CtdlGetConfigInt("c_twitdetect")
204#define TWITROOM CtdlGetConfigStr("c_twitroom")
205#define RESTRICT_INTERNET CtdlGetConfigInt("c_restrict")
206
207#define CtdlREGISTERRoomCfgType(a, p, uniq, nSegs, s, d) RegisterRoomCfgType(#a, sizeof(#a) - 1, a, p, uniq, nSegs, s, d);
208
209
210// Expose API calls from user_ops.c
211int CtdlGetUser(struct ctdluser *usbuf, char *name);
212int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len);
213int CtdlGetUserLock(struct ctdluser *usbuf, char *name);
214void CtdlPutUser(struct ctdluser *usbuf);
215void CtdlPutUserLock(struct ctdluser *usbuf);
216int CtdlLockGetCurrentUser(void);
217void CtdlPutCurrentUserLock(void);
218int CtdlGetUserByNumber(struct ctdluser *usbuf, long number);
219void CtdlGetRelationship(struct visit *vbuf, struct ctdluser *rel_user, struct ctdlroom *rel_room);
220void CtdlSetRelationship(struct visit *newvisit, struct ctdluser *rel_user, struct ctdlroom *rel_room);
221void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix);
222int CtdlLoginExistingUser(const char *username);
223
224// Values which may be returned by CtdlLoginExistingUser()
225enum {
232
233int CtdlTryPassword(const char *password, long len);
234
235// Values which may be returned by CtdlTryPassword()
236enum {
242
243void CtdlUserLogout(void);
244
245
246// Expose API calls from euidindex.c
247long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf);
248
249
250// Expose API calls from external authentication driver
251int attach_extauth(struct ctdluser *who, StrBuf *claimed_id);
252
253#endif
void CtdlGetRelationship(struct visit *vbuf, struct ctdluser *rel_user, struct ctdlroom *rel_room)
Definition user_ops.c:236
int CtdlAccessCheck(int)
Definition user_ops.c:292
void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc)(void *arg))
void CtdlPutUser(struct ctdluser *usbuf)
Definition user_ops.c:86
void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response)
void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix)
Definition user_ops.c:263
int CtdlLockGetCurrentUser(void)
Definition user_ops.c:68
void CtdlGetFloor(struct floor *flbuf, int floor_num)
Definition room_ops.c:434
void CtdlShutdownServiceHooks(void)
void CtdlSetRelationship(struct visit *newvisit, struct ctdluser *rel_user, struct ctdlroom *rel_room)
Definition user_ops.c:223
void CtdlRegisterCleanupHook(void(*fcn_ptr)(void))
int attach_extauth(struct ctdluser *who, StrBuf *claimed_id)
void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig)
Definition netconfig.c:27
int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name)
Definition room_ops.c:302
int CtdlIsUserLoggedInByNum(long usernum)
Definition context.c:152
@ pass_internal_error
@ pass_ok
@ pass_no_user
@ pass_already_logged_in
@ pass_wrong_password
long CtdlGetCurrentMessageNumber(void)
Definition control.c:172
int CtdlGetUserByNumber(struct ctdluser *usbuf, long number)
Definition user_ops.c:356
int CtdlWantSingleUser(void)
Definition context.c:52
int CtdlGetFloorByName(const char *floor_name)
Definition room_ops.c:392
void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf)
Definition room_ops.c:931
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:52
void CtdlDisableHouseKeeping(void)
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:94
void CtdlRegisterSessionHook(void(*fcn_ptr)(void), int EventType, int Priority)
void CtdlRegisterFixedOutputHook(char *content_type, void(*output_function)(char *supplied_data, int len))
void CtdlRegisterRoomHook(int(*fcn_ptr)(struct ctdlroom *))
void CtdlUserLogout(void)
Definition user_ops.c:617
int CtdlGetUserLock(struct ctdluser *usbuf, char *name)
Definition user_ops.c:74
void CtdlRegisterMessageHook(int(*handler)(struct CtdlMessage *, struct recptypes *), int EventType)
int threading
void CtdlDeleteRoom(struct ctdlroom *qrbuf)
Definition room_ops.c:959
void CtdlEnableHouseKeeping(void)
int CtdlGetAvailableFloor(void)
Definition room_ops.c:417
void CtdlFillSystemContext(struct CitContext *context, char *name)
Definition context.c:431
void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *result, int *view)
Definition room_ops.c:98
struct floor * CtdlGetCachedFloor(int floor_num)
Definition room_ops.c:461
void CtdlBumpNewMailCounter(long which_user)
Definition context.c:112
int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name)
Definition room_ops.c:339
void CtdlPutRoom(struct ctdlroom *)
Definition room_ops.c:371
int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr)
Definition room_ops.c:989
int CtdlTrySingleUser(void)
Definition context.c:29
int CtdlTryPassword(const char *password, long len)
Definition user_ops.c:727
void CtdlForEachRoom(ForEachRoomCallBack CB, void *in_data)
Definition room_ops.c:523
@ ac_room_aide
@ ac_none
@ ac_logged_in_or_guest
@ ac_aide
@ ac_logged_in
@ ac_internal
int CtdlGetFloorByNameLock(const char *floor_name)
Definition room_ops.c:409
void CtdlPutUserLock(struct ctdluser *usbuf)
Definition user_ops.c:100
@ login_too_many_users
@ login_not_found
@ login_ok
@ login_already_logged_in
int CtdlIsUserLoggedIn(char *user_name)
Definition context.c:131
void(* ForEachRoomCallBack)(struct ctdlroom *EachRoom, void *out_data)
void CtdlPutFloor(struct floor *flbuf, int floor_num)
Definition room_ops.c:495
@ crr_invalid_floor
@ crr_noneditable
@ crr_room_not_found
@ crr_ok
@ crr_already_exists
@ crr_access_denied
void CtdlRegisterEVCleanupHook(void(*fcn_ptr)(void))
struct CitContext * CtdlGetContextArray(int *count)
Definition context.c:361
int CtdlLoginExistingUser(const char *username)
Definition user_ops.c:419
void CtdlEndSingleUser(void)
Definition context.c:45
int CtdlIsSingleUser(void)
Definition context.c:57
int CtdlRenameRoom(char *old_name, char *new_name, int new_floor)
Definition room_ops.c:819
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:1024
int CtdlIsNonEditable(struct ctdlroom *qrbuf)
Definition room_ops.c:584
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:626
void CtdlRegisterDeleteHook(void(*handler)(char *, long))
int CtdlGetUser(struct ctdluser *usbuf, char *name)
Definition user_ops.c:44
void CtdlPutRoomLock(struct ctdlroom *qrbuf)
Definition room_ops.c:383
void CtdlRegisterUserHook(void(*fcn_ptr)(struct ctdluser *), int EventType)
void CtdlPutFloorLock(struct floor *flbuf, int floor_num)
Definition room_ops.c:509
void CtdlRegisterProtoHook(void(*handler)(char *), char *cmd, char *desc)
Definition server.h:86