The little LEDs on the NanoPi blink when there is activity.
[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 // 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
87 void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType, int Priority);
88 void CtdlShutdownServiceHooks(void);
89 void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
90 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
91 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *, struct recptypes *), int EventType);
92 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
93 void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
94 void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
95 void CtdlRegisterEVCleanupHook(void (*fcn_ptr)(void));
96 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
97 void 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 );
104 void CtdlRegisterFixedOutputHook(char *content_type, void (*output_function) (char *supplied_data, int len));
105 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
106
107 void CtdlDisableHouseKeeping(void);             // If you call this, it may take a while...
108 void 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
112 void 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.
120 struct CitContext *CtdlGetContextArray (int *count);
121 void CtdlFillSystemContext(struct CitContext *context, char *name);
122 int CtdlTrySingleUser(void);
123 void CtdlEndSingleUser(void);
124 int CtdlWantSingleUser(void);
125 int CtdlIsSingleUser(void);
126
127
128 int CtdlIsUserLoggedIn (char *user_name);
129 int CtdlIsUserLoggedInByNum (long usernum);
130 void 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
138 long CtdlGetCurrentMessageNumber(void);
139
140
141
142 // Expose various room operation functions from room_ops.c to the modules API
143
144 unsigned 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);
151 int CtdlGetRoom(struct ctdlroom *qrbuf, const char *room_name);
152 int CtdlGetRoomLock(struct ctdlroom *qrbuf, const char *room_name);
153 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr);
154 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf, int *result, int *view);
155 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
156 typedef void (*ForEachRoomCallBack)(struct ctdlroom *EachRoom, void *out_data);
157 void CtdlForEachRoom(ForEachRoomCallBack CB, void *in_data);
158 char *LoadRoomNetConfigFile(long roomnum);
159 void SaveRoomNetConfigFile(long roomnum, const char *raw_netconfig);
160 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
161 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
162 void CtdlUserGoto (char *where, int display_result, int transiently, int *msgs, int *new, long *oldest, long *newest);
163 struct floor *CtdlGetCachedFloor(int floor_num);
164 void CtdlScheduleRoomForDeletion(struct ctdlroom *qrbuf);
165 void CtdlGetFloor (struct floor *flbuf, int floor_num);
166 void CtdlPutFloor (struct floor *flbuf, int floor_num);
167 void CtdlPutFloorLock(struct floor *flbuf, int floor_num);
168 int CtdlGetFloorByName(const char *floor_name);
169 int CtdlGetFloorByNameLock(const char *floor_name);
170 int CtdlGetAvailableFloor(void);
171 int CtdlIsNonEditable(struct ctdlroom *qrbuf);
172 void CtdlPutRoom(struct ctdlroom *);
173
174 // Possible return values for CtdlRenameRoom()
175 enum {
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
182 };
183
184
185
186 // API declarations from citserver.h
187 int CtdlAccessCheck(int);
188
189 // 'required access level' values which may be passed to CtdlAccessCheck()
190 enum {
191         ac_none,
192         ac_logged_in_or_guest,
193         ac_logged_in,
194         ac_room_aide,
195         ac_aide,
196         ac_internal,
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
211 int CtdlGetUser(struct ctdluser *usbuf, char *name);
212 int CtdlGetUserLen(struct ctdluser *usbuf, const char *name, long len);
213 int CtdlGetUserLock(struct ctdluser *usbuf, char *name);
214 void CtdlPutUser(struct ctdluser *usbuf);
215 void CtdlPutUserLock(struct ctdluser *usbuf);
216 int CtdlLockGetCurrentUser(void);
217 void CtdlPutCurrentUserLock(void);
218 int CtdlGetUserByNumber(struct ctdluser *usbuf, long number);
219 void CtdlGetRelationship(struct visit *vbuf, struct ctdluser *rel_user, struct ctdlroom *rel_room);
220 void CtdlSetRelationship(struct visit *newvisit, struct ctdluser *rel_user, struct ctdlroom *rel_room);
221 void CtdlMailboxName(char *buf, size_t n, const struct ctdluser *who, const char *prefix);
222 int CtdlLoginExistingUser(const char *username);
223
224 // Values which may be returned by CtdlLoginExistingUser()
225 enum {
226         pass_ok,
227         pass_already_logged_in,
228         pass_no_user,
229         pass_internal_error,
230         pass_wrong_password
231 };
232
233 int CtdlTryPassword(const char *password, long len);
234
235 // Values which may be returned by CtdlTryPassword()
236 enum {
237         login_ok,
238         login_already_logged_in,
239         login_too_many_users,
240         login_not_found
241 };
242
243 void CtdlUserLogout(void);
244
245
246 // Expose API calls from euidindex.c
247 long CtdlLocateMessageByEuid(char *euid, struct ctdlroom *qrbuf);
248
249
250 // Expose API calls from external authentication driver
251 int attach_extauth(struct ctdluser *who, StrBuf *claimed_id);
252
253 #endif