* change CtdlReadMessageBody to use StrBuf for concattenating the lines
[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 void cputbuf(const StrBuf *Buf);
44
45 #ifdef __GNUC__
46 void cprintf (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
47 #else
48 void cprintf (const char *format, ...);
49 #endif
50
51 void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...);
52 void vCtdlLogPrintf (enum LogLevel loglevel, const char *format, va_list arg_ptr);
53
54 extern int enable_syslog;
55
56 void init_sysdep (void);
57 int ig_tcp_server (char *ip_addr, int port_number, int queue_len,char **errormessage);
58 int ig_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 sysdep_master_cleanup (void);
69 void kill_session (int session_to_kill);
70 void start_daemon (int do_close_stdio);
71 void checkcrash(void);
72 void cmd_nset (char *cmdbuf);
73 int convert_login (char *NameToConvert);
74 void *worker_thread (void *arg);
75 void init_master_fdset(void);
76 void create_worker(void);
77 void *select_on_master (void *arg);
78
79 extern volatile int exit_signal;
80 extern volatile int shutdown_and_halt;
81 extern volatile int running_as_daemon;
82 extern volatile int restart_server;
83
84 extern int verbosity;
85 extern int rescan[];
86
87
88
89
90 extern int SyslogFacility(char *name);
91 extern int syslog_facility;
92
93
94 /*
95  * Typdefs and stuff to abstract pthread for Citadel
96  */
97 #ifdef HAVE_PTHREAD_H
98
99 typedef pthread_t       citthread_t;
100 typedef pthread_key_t   citthread_key_t;
101 typedef pthread_mutex_t citthread_mutex_t;
102 typedef pthread_cond_t  citthread_cond_t;
103 typedef pthread_attr_t  citthread_attr_t;
104
105
106 #define citthread_mutex_init    pthread_mutex_init
107 #define citthread_cond_init     pthread_cond_init
108 #define citthread_attr_init     pthread_attr_init
109 #define citthread_mutex_trylock pthread_mutex_trylock
110 #define citthread_mutex_lock    pthread_mutex_lock
111 #define citthread_mutex_unlock  pthread_mutex_unlock
112 #define citthread_key_create    pthread_key_create
113 #define citthread_getspecific   pthread_getspecific
114 #define citthread_setspecific   pthread_setspecific
115 #define citthread_mutex_destroy pthread_mutex_destroy
116 #define citthread_cond_destroy  pthread_cond_destroy
117 #define citthread_attr_destroy  pthread_attr_destroy
118
119 #define citthread_kill          pthread_kill
120 #define citthread_cond_signal   pthread_cond_signal
121 #define citthread_cancel        pthread_cancel
122 #define citthread_cond_timedwait        pthread_cond_timedwait
123 #define citthread_equal         pthread_equal
124 #define citthread_self          pthread_self
125 #define citthread_create        pthread_create
126 #define citthread_attr_setstacksize     pthread_attr_setstacksize
127 #define citthread_join          pthread_join
128 #define citthread_cleanup_push  pthread_cleanup_push
129 #define citthread_cleanup_pop   pthread_cleanup_pop
130
131
132 #endif /* HAVE_PTHREAD_H */
133
134
135 #ifdef DEBUG_MEMORY_LEAKS
136 #define malloc(x) tracked_malloc(x, __FILE__, __LINE__)
137 #define realloc(x,y) tracked_realloc(x, y, __FILE__, __LINE__)
138 #undef strdup
139 #define strdup(x) tracked_strdup(x, __FILE__, __LINE__)
140 #define free(x) tracked_free(x)
141 void *tracked_malloc(size_t size, char *file, int line);
142 void *tracked_realloc(void *ptr, size_t size, char *file, int line);
143 void tracked_free(void *ptr);
144 char *tracked_strdup(const char *s, char *file, int line);
145 void dump_heap(void);
146 #endif
147
148 #endif /* SYSDEP_DECLS_H */