System users (SYS_*) now have proper user numbers.
[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 /*
31  * Fix the interface to aide_message so that it complies with the Coding style
32  */
33  
34 #define CtdlAideMessage(TEXT, SUBJECT) aide_message(TEXT, SUBJECT)
35
36 /*
37  * Hook functions available to modules.
38  */
39
40 void CtdlRegisterSessionHook(void (*fcn_ptr)(void), int EventType);
41 void CtdlUnregisterSessionHook(void (*fcn_ptr)(void), int EventType);
42
43 void CtdlRegisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
44 void CtdlUnregisterUserHook(void (*fcn_ptr)(struct ctdluser *), int EventType);
45
46 void CtdlRegisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
47 void CtdlUnregisterXmsgHook(int (*fcn_ptr)(char *, char *, char *, char *), int order);
48
49 void CtdlRegisterMessageHook(int (*handler)(struct CtdlMessage *),
50                                                         int EventType);
51 void CtdlUnregisterMessageHook(int (*handler)(struct CtdlMessage *),
52                                                         int EventType);
53
54 void CtdlRegisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
55 void CtdlUnregisterNetprocHook(int (*handler)(struct CtdlMessage *, char *) );
56
57 void CtdlRegisterRoomHook(int (*fcn_ptr)(struct ctdlroom *) );
58 void CtdlUnregisterRoomHook(int (*fnc_ptr)(struct ctdlroom *) );
59
60 void CtdlRegisterDeleteHook(void (*handler)(char *, long) );
61 void CtdlUnregisterDeleteHook(void (*handler)(char *, long) );
62
63 void CtdlRegisterCleanupHook(void (*fcn_ptr)(void));
64 void CtdlUnregisterCleanupHook(void (*fcn_ptr)(void));
65
66 void CtdlRegisterProtoHook(void (*handler)(char *), char *cmd, char *desc);
67 void CtdlUnregisterProtoHook(void (*handler)(char *), char *cmd);
68
69 void CtdlRegisterServiceHook(int tcp_port,
70                              char *sockpath,
71                              void (*h_greeting_function) (void),
72                              void (*h_command_function) (void),
73                              void (*h_async_function) (void),
74                              const char *ServiceName
75 );
76 void CtdlUnregisterServiceHook(int tcp_port,
77                         char *sockpath,
78                         void (*h_greeting_function) (void),
79                         void (*h_command_function) (void),
80                         void (*h_async_function) (void)
81 );
82
83 void CtdlRegisterFixedOutputHook(char *content_type,
84                         void (*output_function) (char *supplied_data, int len)
85 );
86 void CtdlUnRegisterFixedOutputHook(char *content_type);
87
88 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
89
90 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name);
91
92
93 /*
94  * Directory services hooks for LDAP etc
95  */
96
97 #define DIRECTORY_USER_DEL 1    // Delete a user entry
98 #define DIRECTORY_CREATE_HOST 2 // Create a host entry if not already there.
99 #define DIRECTORY_CREATE_OBJECT 3       // Create a new object for directory entry
100 #define DIRECTORY_ATTRIB_ADD 4  // Add an attribute to the directory entry object
101 #define DIRECTORY_SAVE_OBJECT 5 // Save the object to the directory service
102 #define DIRECTORY_FREE_OBJECT 6 // Free the object and its attributes
103
104 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module);
105 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd);
106
107 /* TODODRW: This needs to be changed into a hook type interface
108  * for now we have this horrible hack
109  */
110 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
111
112
113 /*
114  * Citadel Threads API
115  */
116 struct CtdlThreadNode *CtdlThreadCreate(char *name, long flags, void *(*thread_func) (void *arg), void *args);
117 struct CtdlThreadNode *CtdlThreadSchedule(char *name, long flags, void *(*thread_func) (void *arg), void *args, time_t when);
118 void CtdlThreadSleep(int secs);
119 void CtdlThreadStop(struct CtdlThreadNode *thread);
120 int CtdlThreadCheckStop(void);
121 /* void CtdlThreadCancel2(struct CtdlThreadNode *thread); Leave this out, it should never be needed */
122 const char *CtdlThreadName(const char *name);
123 struct CtdlThreadNode *CtdlThreadSelf(void);
124 int CtdlThreadGetCount(void);
125 int CtdlThreadGetWorkers(void);
126 double CtdlThreadGetWorkerAvg(void);
127 double CtdlThreadGetLoadAvg(void);
128 void CtdlThreadGC(void);
129 void CtdlThreadStopAll(void);
130 int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
131 void CtdlThreadAllocTSD(void);
132
133 #define CTDLTHREAD_BIGSTACK     0x0001
134 #define CTDLTHREAD_WORKER       0x0002
135
136 /* Macros to speed up getting outr thread */
137
138 #define MYCURSORS       (((ThreadTSD*)pthread_getspecific(ThreadKey))->cursors)
139 #define MYTID           (((ThreadTSD*)pthread_getspecific(ThreadKey))->tid)
140 #define CT              (((ThreadTSD*)pthread_getspecific(ThreadKey))->self)
141
142 /** return the current context list as an array and do it in a safe manner
143  * The returned data is a copy so only reading is useful
144  * The number of contexts is returned in count.
145  * Beware, this does not copy any of the data pointed to by the context.
146  * This means that you can not rely on things like the redirect buffer being valid.
147  * You must free the returned pointer when done.
148  */
149 struct CitContext *CtdlGetContextArray (int *count);
150 void CtdlFillSystemContext(struct CitContext *context, char *name);
151
152
153
154 /*
155  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
156  * This provides a quick way to initialise a variable that might be used to indicate
157  * messages that should not be processed. EG. a new Sieve script will use this
158  * to record determine that messages older than this should not be processed.
159  * This function is defined in control.c
160  */
161 long CtdlGetCurrentMessageNumber(void);
162
163 #endif /* CTDL_MODULE_H */