* give all commands their own function
[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
68 void CtdlRegisterServiceHook(int tcp_port,
69                              char *sockpath,
70                              void (*h_greeting_function) (void),
71                              void (*h_command_function) (void),
72                              void (*h_async_function) (void),
73                              const char *ServiceName
74 );
75 void CtdlUnregisterServiceHook(int tcp_port,
76                         char *sockpath,
77                         void (*h_greeting_function) (void),
78                         void (*h_command_function) (void),
79                         void (*h_async_function) (void)
80 );
81
82 void CtdlRegisterFixedOutputHook(char *content_type,
83                         void (*output_function) (char *supplied_data, int len)
84 );
85 void CtdlUnRegisterFixedOutputHook(char *content_type);
86
87 void CtdlRegisterMaintenanceThread(char *name, void *(*thread_proc) (void *arg));
88
89 void CtdlRegisterSearchFuncHook(void (*fcn_ptr)(int *, long **, char *), char *name);
90
91
92 /*
93  * Directory services hooks for LDAP etc
94  */
95
96 #define DIRECTORY_USER_DEL 1    // Delete a user entry
97 #define DIRECTORY_CREATE_HOST 2 // Create a host entry if not already there.
98 #define DIRECTORY_CREATE_OBJECT 3       // Create a new object for directory entry
99 #define DIRECTORY_ATTRIB_ADD 4  // Add an attribute to the directory entry object
100 #define DIRECTORY_SAVE_OBJECT 5 // Save the object to the directory service
101 #define DIRECTORY_FREE_OBJECT 6 // Free the object and its attributes
102
103 int CtdlRegisterDirectoryServiceFunc(int (*func)(char *cn, char *ou, void **object), int cmd, char *module);
104 int CtdlDoDirectoryServiceFunc(char *cn, char *ou, void **object, char *module, int cmd);
105
106 /* TODODRW: This needs to be changed into a hook type interface
107  * for now we have this horrible hack
108  */
109 void CtdlModuleStartCryptoMsgs(char *ok_response, char *nosup_response, char *error_response);
110
111
112 /*
113  * Citadel Threads API
114  */
115 struct CtdlThreadNode *CtdlThreadCreate(char *name, long flags, void *(*thread_func) (void *arg), void *args);
116 struct CtdlThreadNode *CtdlThreadSchedule(char *name, long flags, void *(*thread_func) (void *arg), void *args, time_t when);
117 void CtdlThreadSleep(int secs);
118 void CtdlThreadStop(struct CtdlThreadNode *thread);
119 int CtdlThreadCheckStop(void);
120 /* void CtdlThreadCancel2(struct CtdlThreadNode *thread); Leave this out, it should never be needed */
121 const char *CtdlThreadName(const char *name);
122 struct CtdlThreadNode *CtdlThreadSelf(void);
123 int CtdlThreadGetCount(void);
124 int CtdlThreadGetWorkers(void);
125 double CtdlThreadGetWorkerAvg(void);
126 double CtdlThreadGetLoadAvg(void);
127 void CtdlThreadGC(void);
128 void CtdlThreadStopAll(void);
129 int CtdlThreadSelect(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
130 void CtdlThreadAllocTSD(void);
131
132 #define CTDLTHREAD_BIGSTACK     0x0001
133 #define CTDLTHREAD_WORKER       0x0002
134
135 /* Macros to speed up getting outr thread */
136
137 #define MYCURSORS       (((ThreadTSD*)pthread_getspecific(ThreadKey))->cursors)
138 #define MYTID           (((ThreadTSD*)pthread_getspecific(ThreadKey))->tid)
139 #define CT              (((ThreadTSD*)pthread_getspecific(ThreadKey))->self)
140
141 /** return the current context list as an array and do it in a safe manner
142  * The returned data is a copy so only reading is useful
143  * The number of contexts is returned in count.
144  * Beware, this does not copy any of the data pointed to by the context.
145  * This means that you can not rely on things like the redirect buffer being valid.
146  * You must free the returned pointer when done.
147  */
148 struct CitContext *CtdlGetContextArray (int *count);
149 void CtdlFillSystemContext(struct CitContext *context, char *name);
150
151 int CtdlTrySingleUser(void);
152 void CtdlEndSingleUser(void);
153 int CtdlWantSingleUser(void);
154 int CtdlIsSingleUser(void);
155
156
157 /*
158  * CtdlGetCurrentMessageNumber()  -  Obtain the current highest message number in the system
159  * This provides a quick way to initialise a variable that might be used to indicate
160  * messages that should not be processed. EG. a new Sieve script will use this
161  * to record determine that messages older than this should not be processed.
162  * This function is defined in control.c
163  */
164 long CtdlGetCurrentMessageNumber(void);
165
166 #endif /* CTDL_MODULE_H */