Moved all threading code into threads.c
[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 <pthread.h>
15 #include <stdarg.h>
16 #include "sysdep.h"
17
18 #ifdef HAVE_DB_H
19 #include <db.h>
20 #elif defined(HAVE_DB4_DB_H)
21 #include <db4/db.h>
22 #else
23 #error Neither <db.h> nor <db4/db.h> was found by configure. Install db4-devel.
24 #endif
25
26
27 #if DB_VERSION_MAJOR < 4 || DB_VERSION_MINOR < 1
28 #error Citadel requires Berkeley DB v4.1 or newer.  Please upgrade.
29 #endif
30
31 #include "server.h"
32 #include "database.h"
33
34 #if SIZEOF_SIZE_T == SIZEOF_INT 
35 #define SIZE_T_FMT "%d"
36 #else
37 #define SIZE_T_FMT "%ld"
38 #endif
39
40
41 /* Logging levels - correspond to syslog(3) */
42 enum LogLevel {
43         /* When about to exit the server for an unrecoverable error */
44          CTDL_EMERG,    /* system is unusable */
45         /* Manual intervention is required to avoid an abnormal exit */
46          CTDL_ALERT,    /* action must be taken immediately */
47         /* The server can continue to run with degraded functionality */
48          CTDL_CRIT,     /* critical conditions */
49         /* An error occurs but the server continues to run normally */
50          CTDL_ERR,      /* error conditions */
51         /* An abnormal condition was detected; server will continue normally */
52          CTDL_WARNING,  /* warning conditions */
53         /* Normal messages (login/out, activity, etc.) */
54          CTDL_NOTICE,   /* normal but significant condition */
55         /* Unimportant progress messages, etc. */
56          CTDL_INFO,     /* informational */
57         /* Debugging messages */
58          CTDL_DEBUG     /* debug-level messages */
59 };
60
61 #ifdef __GNUC__
62 void lprintf (enum LogLevel loglevel, const char *format, ...) __attribute__((__format__(__printf__,2,3)));
63 void cprintf (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
64 #else
65 void lprintf (enum LogLevel loglevel, const char *format, ...);
66 void cprintf (const char *format, ...);
67 #endif
68
69 void vlprintf (enum LogLevel loglevel, const char *format, va_list arg_ptr);
70
71 extern pthread_key_t MyConKey;                  /* TSD key for MyContext() */
72
73 extern int enable_syslog;
74
75 void init_sysdep (void);
76 int ig_tcp_server (char *ip_addr, int port_number, int queue_len,char **errormessage);
77 int ig_uds_server(char *sockpath, int queue_len, char **errormessage);
78 struct CitContext *MyContext (void);
79 struct CitContext *CreateNewContext (void);
80 void InitMyContext (struct CitContext *con);
81 void buffer_output(void);
82 void unbuffer_output(void);
83 void flush_output(void);
84 void client_write (char *buf, int nbytes);
85 int client_read_to (char *buf, int bytes, int timeout);
86 int client_read (char *buf, int bytes);
87 int client_getln (char *buf, int maxbytes);
88 void sysdep_master_cleanup (void);
89 void kill_session (int session_to_kill);
90 void *sd_context_loop (struct CitContext *con);
91 void start_daemon (int do_close_stdio);
92 void cmd_nset (char *cmdbuf);
93 int convert_login (char *NameToConvert);
94 void *worker_thread (void *arg);
95 void *context_cleanup_thread (void *arg);
96 void become_session(struct CitContext *which_con);
97 void InitializeMasterCC(void);
98 void init_master_fdset(void);
99 void create_worker(void);
100
101
102 extern int num_sessions;
103 extern volatile int exit_signal;
104 extern volatile int shutdown_and_halt;
105 extern volatile int running_as_daemon;
106 extern volatile int restart_server;
107
108 extern int verbosity;
109 extern int rescan[];
110
111
112
113
114 extern int SyslogFacility(char *name);
115 extern int syslog_facility;
116
117 #ifdef DEBUG_MEMORY_LEAKS
118 #define malloc(x) tracked_malloc(x, __FILE__, __LINE__)
119 #define realloc(x,y) tracked_realloc(x, y, __FILE__, __LINE__)
120 #undef strdup
121 #define strdup(x) tracked_strdup(x, __FILE__, __LINE__)
122 #define free(x) tracked_free(x)
123 void *tracked_malloc(size_t size, char *file, int line);
124 void *tracked_realloc(void *ptr, size_t size, char *file, int line);
125 void tracked_free(void *ptr);
126 char *tracked_strdup(const char *s, char *file, int line);
127 void dump_heap(void);
128 #endif
129
130 void create_maintenance_threads(void);
131
132 #endif /* SYSDEP_DECLS_H */