Fix the Makefile.in to properly clean the user_modules tree.
[citadel.git] / citadel / include / ctdl_module.h
1 /* $Id$ */
2
3 #ifndef CTDL_MODULE_H
4 #define CTDL_MODULE_H
5
6 #include <libcitadel.h>
7 #include "server.h"
8 #include "sysdep_decls.h"
9 #include "msgbase.h"
10 #include "threads.h"
11 /*
12  * define macros for module init stuff
13  */
14  
15 #define CTDL_MODULE_INIT(module_name) char *ctdl_module_##module_name##_init (int threading)
16
17 #define CTDL_INIT_CALL(module_name) ctdl_module_##module_name##_init (threading)
18
19 #define CTDL_MODULE_UPGRADE(module_name) char *ctdl_module_##module_name##_upgrade (void)
20
21 #define CTDL_UPGRADE_CALL(module_name) ctdl_module_##module_name##_upgrade ()
22
23
24 /*
25  * Prototype for making log entries in Citadel.
26  */
27
28 void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...);
29
30 #define CtdlAideMessage(TEXT, SUBJECT) quickie_message("Citadel",NULL,NULL,AIDEROOM,TEXT,FMT_CITADEL,SUBJECT) 
31
32 /*
33  * Hook functions available to modules.
34  */
35
36 void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType);
37 void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
38
39 void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
40 void CtdlUnregisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
41
42 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
43 void CtdlUnregisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
44
45 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
46                                                         int EventType);
47 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
48                                                         int EventType);
49
50 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
51 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
52
53 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
54 void CtdlUnregisterRoomHook(int (*fnc_ptr)(struct ctdlroom *) );
55
56 void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
57 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) );
58
59 void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
60 void CtdlUnregisterCleanupHook(void (*fcn_ptr)(void));
61
62 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
63
64 void CtdlRegisterServiceHook(int tcp_port,
65                              char *sockpath,
66                              void (*h_greeting_function) (void),
67                              void (*h_command_function) (void),
68                              void (*h_async_function) (void),
69                              const char *ServiceName
70 );
71 void CtdlUnregisterServiceHook(int tcp_port,
72                         char *sockpath,
73                         void (*h_greeting_function) (void),
74                         void (*h_command_function) (void),
75                         void (*h_async_function) (void)
76 );
77
78 void CtdlRegisterFixedOutputHook(char *content_type,
79                         void (*output_function) (char *supplied_data, int len)
80 );
81 void CtdlUnRegisterFixedOutputHook(char *content_type);
82
83 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
84
85 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name);
86
87
88 /*
89  * Directory services hooks for LDAP etc
90  */
91
92 #define DIRECTORY_USER_DEL 1    // Delete a user entry
93 #define DIRECTORY_CREATE_HOST 2 // Create a host entry if not already there.
94 #define DIRECTORY_CREATE_OBJECT 3       // Create a new object for directory entry
95 #define DIRECTORY_ATTRIB_ADD 4  // Add an attribute to the directory entry object
96 #define DIRECTORY_SAVE_OBJECT 5 // Save the object to the directory service
97 #define DIRECTORY_FREE_OBJECT 6 // Free the object and its attributes
98
99 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module);
100 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd);
101
102 /* TODODRW: This needs to be changed into a hook type interface
103  * for now we have this horrible hack
104  */
105 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
106
107
108 /*
109  * Citadel Threads API
110  */
111 struct CtdlThreadNode *CtdlThreadCreate(char *name, long flags, void *(*thread_func) (void *arg), void *args);
112 struct CtdlThreadNode *CtdlThreadSchedule(char *name, long flags, void *(*thread_func) (void *arg), void *args, time_t when);
113 void CtdlThreadSleep(int secs);
114 void CtdlThreadStop(struct CtdlThreadNode *thread);
115 int CtdlThreadCheckStop(void);
116 /* void CtdlThreadCancel2(struct CtdlThreadNode *thread); Leave this out, it should never be needed */
117 const char *CtdlThreadName(const char *name);
118 struct CtdlThreadNode *CtdlThreadSelf(void);
119 int CtdlThreadGetCount(void);
120 int CtdlThreadGetWorkers(void);
121 double CtdlThreadGetWorkerAvg(void);
122 double CtdlThreadGetLoadAvg(void);
123 void CtdlThreadGC(void);
124 void CtdlThreadStopAll(void);
125 int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
126 void CtdlThreadAllocTSD(void);
127
128 #define CTDLTHREAD_BIGSTACK     0x0001
129 #define CTDLTHREAD_WORKER       0x0002
130
131 /* Macros to speed up getting outr thread */
132
133 #define MYCURSORS       (((ThreadTSD*)pthread_getspecific(ThreadKey))->cursors)
134 #define MYTID           (((ThreadTSD*)pthread_getspecific(ThreadKey))->tid)
135 #define CT              (((ThreadTSD*)pthread_getspecific(ThreadKey))->self)
136
137 /** return the current context list as an array and do it in a safe manner
138  * The returned data is a copy so only reading is useful
139  * The number of contexts is returned in count.
140  * Beware, this does not copy any of the data pointed to by the context.
141  * This means that you can not rely on things like the redirect buffer being valid.
142  * You must free the returned pointer when done.
143  */
144 struct CitContext *CtdlGetContextArray (int *count);
145 void CtdlFillSystemContext(struct CitContext *context, char *name);
146
147 int CtdlTrySingleUser(void);
148 void CtdlEndSingleUser(void);
149 int CtdlWantSingleUser(void);
150 int CtdlIsSingleUser(void);
151
152
153 /*
154  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
155  * This provides a quick way to initialise a variable that might be used to indicate
156  * messages that should not be processed. EG. a new Sieve 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, char *room_name);
176 int CtdlGetRoomLock(struct ctdlroom *qrbuf, char *room_name);
177 int CtdlDoIHavePermissionToDeleteThisRoom(struct ctdlroom *qr);
178 void CtdlRoomAccess(struct ctdlroom *roombuf, struct ctdluser *userbuf,
179                 int *result, int *view);
180 void CtdlPutRoomLock(struct ctdlroom *qrbuf);
181 void CtdlForEachRoom(void (*CallBack)(struct ctdlroom *EachRoom, void *out_data),
182         void *in_data);
183 void CtdlDeleteRoom(struct ctdlroom *qrbuf);
184 int CtdlRenameRoom(char *old_name, char *new_name, int new_floor);
185 void CtdlUserGoto (char *where, int display_result, int transiently,
186                         int *msgs, int *new);
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 int CtdlIsNonEditable(struct ctdlroom *qrbuf);
192 void CtdlPutRoom(struct ctdlroom *);
193
194 /*
195  * Possible return values for CtdlRenameRoom()
196  */
197 enum {
198         crr_ok,                         /* success */
199         crr_room_not_found,             /* room not found */
200         crr_already_exists,             /* new name already exists */
201         crr_noneditable,                /* cannot edit this room */
202         crr_invalid_floor,              /* target floor does not exist */
203         crr_access_denied               /* not allowed to edit this room */
204 };
205
206 #endif /* CTDL_MODULE_H */