Began removing $Id$ tags. This will be an ongoing process.
[citadel.git] / citadel / sysdep_decls.h
1
2 #ifndef SYSDEP_DECLS_H
3 #define SYSDEP_DECLS_H
4
5 /*
6  * Uncomment this #define if you are a Citadel developer tracking
7  * down memory leaks in the server.  Do NOT do this on a production
8  * system because it definitely incurs a lot of additional overhead.
9 #define DEBUG_MEMORY_LEAKS
10  */
11
12
13 #include <stdarg.h>
14 #include "sysdep.h"
15
16 #ifdef HAVE_PTHREAD_H
17 #include <pthread.h>
18 #endif
19
20 #ifdef HAVE_DB_H
21 #include <db.h>
22 #elif defined(HAVE_DB4_DB_H)
23 #include <db4/db.h>
24 #else
25 #error Neither <db.h> nor <db4/db.h> was found by configure. Install db4-devel.
26 #endif
27
28
29 #if DB_VERSION_MAJOR < 4 || DB_VERSION_MINOR < 1
30 #error Citadel requires Berkeley DB v4.1 or newer.  Please upgrade.
31 #endif
32
33 #include "server.h"
34 #include "database.h"
35
36 #if SIZEOF_SIZE_T == SIZEOF_INT 
37 #define SIZE_T_FMT "%d"
38 #else
39 #define SIZE_T_FMT "%ld"
40 #endif
41
42 void cputbuf(const StrBuf *Buf);
43
44 #ifdef __GNUC__
45 void cprintf (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
46 #else
47 void cprintf (const char *format, ...);
48 #endif
49
50 void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...);
51 void vCtdlLogPrintf (enum LogLevel loglevel, const char *format, va_list arg_ptr);
52
53 extern int enable_syslog;
54 extern int print_to_logfile;
55
56 void init_sysdep (void);
57 int ctdl_tcp_server(char *ip_addr, int port_number, int queue_len, char *errormessage);
58 int ctdl_uds_server(char *sockpath, int queue_len, char *errormessage);
59 void buffer_output(void);
60 void unbuffer_output(void);
61 void flush_output(void);
62 int client_write (const char *buf, int nbytes);
63 int client_read_to (char *buf, int bytes, int timeout);
64 int client_read (char *buf, int bytes);
65 int client_getln (char *buf, int maxbytes);
66 int CtdlClientGetLine(StrBuf *Target);
67 int client_read_blob(StrBuf *Target, int bytes, int timeout);
68 void client_set_inbound_buf(long N);
69 int client_read_random_blob(StrBuf *Target, int timeout);
70 void sysdep_master_cleanup (void);
71 void kill_session (int session_to_kill);
72 void start_daemon (int do_close_stdio);
73 void checkcrash(void);
74 void cmd_nset (char *cmdbuf);
75 int convert_login (char *NameToConvert);
76 void *worker_thread (void *arg);
77 void init_master_fdset(void);
78 void create_worker(void);
79 void *select_on_master (void *arg);
80
81 extern volatile int exit_signal;
82 extern volatile int shutdown_and_halt;
83 extern volatile int running_as_daemon;
84 extern volatile int restart_server;
85
86 extern int verbosity;
87 extern int rescan[];
88
89
90
91
92 extern int SyslogFacility(char *name);
93 extern int syslog_facility;
94
95
96 /*
97  * Typdefs and stuff to abstract pthread for Citadel
98  */
99 #ifdef HAVE_PTHREAD_H
100
101 typedef pthread_t       citthread_t;
102 typedef pthread_key_t   citthread_key_t;
103 typedef pthread_mutex_t citthread_mutex_t;
104 typedef pthread_cond_t  citthread_cond_t;
105 typedef pthread_attr_t  citthread_attr_t;
106
107
108 #define citthread_mutex_init    pthread_mutex_init
109 #define citthread_cond_init     pthread_cond_init
110 #define citthread_attr_init     pthread_attr_init
111 #define citthread_mutex_trylock pthread_mutex_trylock
112 #define citthread_mutex_lock    pthread_mutex_lock
113 #define citthread_mutex_unlock  pthread_mutex_unlock
114 #define citthread_key_create    pthread_key_create
115 #define citthread_getspecific   pthread_getspecific
116 #define citthread_setspecific   pthread_setspecific
117 #define citthread_mutex_destroy pthread_mutex_destroy
118 #define citthread_cond_destroy  pthread_cond_destroy
119 #define citthread_attr_destroy  pthread_attr_destroy
120
121 #define citthread_kill          pthread_kill
122 #define citthread_cond_signal   pthread_cond_signal
123 #define citthread_cancel        pthread_cancel
124 #define citthread_cond_timedwait        pthread_cond_timedwait
125 #define citthread_equal         pthread_equal
126 #define citthread_self          pthread_self
127 #define citthread_create        pthread_create
128 #define citthread_attr_setstacksize     pthread_attr_setstacksize
129 #define citthread_join          pthread_join
130 #define citthread_cleanup_push  pthread_cleanup_push
131 #define citthread_cleanup_pop   pthread_cleanup_pop
132
133
134 #endif /* HAVE_PTHREAD_H */
135
136
137 #ifdef DEBUG_MEMORY_LEAKS
138 #define malloc(x) tracked_malloc(x, __FILE__, __LINE__)
139 #define realloc(x,y) tracked_realloc(x, y, __FILE__, __LINE__)
140 #undef strdup
141 #define strdup(x) tracked_strdup(x, __FILE__, __LINE__)
142 #define free(x) tracked_free(x)
143 void *tracked_malloc(size_t size, char *file, int line);
144 void *tracked_realloc(void *ptr, size_t size, char *file, int line);
145 void tracked_free(void *ptr);
146 char *tracked_strdup(const char *s, char *file, int line);
147 void dump_heap(void);
148 #endif
149
150 #endif /* SYSDEP_DECLS_H */