a20c35cdb46cef5ed904ed29cc2ac8ec078ad68a
[citadel.git] / citadel / sysdep_decls.h
1 /* $Id$ */
2
3 #ifndef SYSDEP_DECLS_H
4 #define SYSDEP_DECLS_H
5
6 /*
7  * Uncomment this #define if you are a Citadel developer tracking
8  * down memory leaks in the server.  Do NOT do this on a production
9  * system because it definitely incurs a lot of additional overhead.
10 #define DEBUG_MEMORY_LEAKS
11  */
12
13
14 #include <stdarg.h>
15 #include "sysdep.h"
16
17 #ifdef HAVE_PTHREAD_H
18 #include <pthread.h>
19 #endif
20
21 #ifdef HAVE_DB_H
22 #include <db.h>
23 #elif defined(HAVE_DB4_DB_H)
24 #include <db4/db.h>
25 #else
26 #error Neither <db.h> nor <db4/db.h> was found by configure. Install db4-devel.
27 #endif
28
29
30 #if DB_VERSION_MAJOR < 4 || DB_VERSION_MINOR < 1
31 #error Citadel requires Berkeley DB v4.1 or newer.  Please upgrade.
32 #endif
33
34 #include "server.h"
35 #include "database.h"
36
37 #if SIZEOF_SIZE_T == SIZEOF_INT 
38 #define SIZE_T_FMT "%d"
39 #else
40 #define SIZE_T_FMT "%ld"
41 #endif
42
43
44 /* Logging levels - correspond to syslog(3) */
45 enum LogLevel {
46         /* When about to exit the server for an unrecoverable error */
47          CTDL_EMERG,    /* system is unusable */
48         /* Manual intervention is required to avoid an abnormal exit */
49          CTDL_ALERT,    /* action must be taken immediately */
50         /* The server can continue to run with degraded functionality */
51          CTDL_CRIT,     /* critical conditions */
52         /* An error occurs but the server continues to run normally */
53          CTDL_ERR,      /* error conditions */
54         /* An abnormal condition was detected; server will continue normally */
55          CTDL_WARNING,  /* warning conditions */
56         /* Normal messages (login/out, activity, etc.) */
57          CTDL_NOTICE,   /* normal but significant condition */
58         /* Unimportant progress messages, etc. */
59          CTDL_INFO,     /* informational */
60         /* Debugging messages */
61          CTDL_DEBUG     /* debug-level messages */
62 };
63
64 #ifdef __GNUC__
65 void cprintf (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
66 #else
67 void cprintf (const char *format, ...);
68 #endif
69
70 void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...);
71 void vCtdlLogPrintf (enum LogLevel loglevel, const char *format, va_list arg_ptr);
72
73 extern pthread_key_t MyConKey;                  /* TSD key for MyContext() */
74
75 extern int enable_syslog;
76
77 void init_sysdep (void);
78 int ig_tcp_server (char *ip_addr, int port_number, int queue_len,char **errormessage);
79 int ig_uds_server(char *sockpath, int queue_len, char **errormessage);
80 struct CitContext *MyContext (void);
81 struct CitContext *CreateNewContext (void);
82 void InitMyContext (struct CitContext *con);
83 void buffer_output(void);
84 void unbuffer_output(void);
85 void flush_output(void);
86 void client_write (char *buf, int nbytes);
87 int client_read_to (char *buf, int bytes, int timeout);
88 int client_read (char *buf, int bytes);
89 int client_getln (char *buf, int maxbytes);
90 void sysdep_master_cleanup (void);
91 void kill_session (int session_to_kill);
92 void *sd_context_loop (struct CitContext *con);
93 void start_daemon (int do_close_stdio);
94 void cmd_nset (char *cmdbuf);
95 int convert_login (char *NameToConvert);
96 void *worker_thread (void *arg);
97 void *context_cleanup_thread (void *arg);
98 void become_session(struct CitContext *which_con);
99 void InitializeMasterCC(void);
100 void init_master_fdset(void);
101 void create_worker(void);
102
103
104 extern int num_sessions;
105 extern volatile int exit_signal;
106 extern volatile int shutdown_and_halt;
107 extern volatile int running_as_daemon;
108 extern volatile int restart_server;
109
110 extern int verbosity;
111 extern int rescan[];
112
113
114
115
116 extern int SyslogFacility(char *name);
117 extern int syslog_facility;
118
119
120 /*
121  * Typdefs and stuff to abstract pthread for Citadel
122  */
123 #ifdef HAVE_PTHREAD_H
124
125 typedef pthread_t       citthread_t;
126 typedef pthread_key_t   citthread_key_t;
127 typedef pthread_mutex_t citthread_mutex_t;
128 typedef pthread_cond_t  citthread_cond_t;
129 typedef pthread_attr_t  citthread_attr_t;
130
131
132 #define citthread_mutex_init    pthread_mutex_init
133 #define citthread_cond_init     pthread_cond_init
134 #define citthread_attr_init     pthread_attr_init
135 #define citthread_mutex_trylock pthread_mutex_trylock
136 #define citthread_mutex_lock    pthread_mutex_lock
137 #define citthread_mutex_unlock  pthread_mutex_unlock
138 #define citthread_key_create    pthread_key_create
139 #define citthread_getspecific   pthread_getspecific
140 #define citthread_setspecific   pthread_setspecific
141 #define citthread_mutex_destroy pthread_mutex_destroy
142 #define citthread_cond_destroy  pthread_cond_destroy
143 #define citthread_attr_destroy  pthread_attr_destroy
144
145 #define citthread_kill          pthread_kill
146 #define citthread_cond_signal   pthread_cond_signal
147 #define citthread_cancel        pthread_cancel
148 #define citthread_cond_timedwait        pthread_cond_timedwait
149 #define citthread_equal         pthread_equal
150 #define citthread_self          pthread_self
151 #define citthread_create        pthread_create
152 #define citthread_attr_setstacksize     pthread_attr_setstacksize
153 #define citthread_join          pthread_join
154 #define citthread_cleanup_push  pthread_cleanup_push
155 #define citthread_cleanup_pop   pthread_cleanup_pop
156
157
158 #endif /* HAVE_PTHREAD_H */
159
160
161 #ifdef DEBUG_MEMORY_LEAKS
162 #define malloc(x) tracked_malloc(x, __FILE__, __LINE__)
163 #define realloc(x,y) tracked_realloc(x, y, __FILE__, __LINE__)
164 #undef strdup
165 #define strdup(x) tracked_strdup(x, __FILE__, __LINE__)
166 #define free(x) tracked_free(x)
167 void *tracked_malloc(size_t size, char *file, int line);
168 void *tracked_realloc(void *ptr, size_t size, char *file, int line);
169 void tracked_free(void *ptr);
170 char *tracked_strdup(const char *s, char *file, int line);
171 void dump_heap(void);
172 #endif
173
174 #endif /* SYSDEP_DECLS_H */