a1e551c9f468467b6fb86b010ae101c405bafe8d
[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 "sysdep.h"
16 #include "server.h"
17
18
19 /* Logging levels - correspond to syslog(3) */
20 enum LogLevel {
21         /* When about to exit the server for an unrecoverable error */
22          CTDL_EMERG,    /* system is unusable */
23         /* Manual intervention is required to avoid an abnormal exit */
24          CTDL_ALERT,    /* action must be taken immediately */
25         /* The server can continue to run with degraded functionality */
26          CTDL_CRIT,     /* critical conditions */
27         /* An error occurs but the server continues to run normally */
28          CTDL_ERR,      /* error conditions */
29         /* An abnormal condition was detected; server will continue normally */
30          CTDL_WARNING,  /* warning conditions */
31         /* Normal messages (login/out, activity, etc.) */
32          CTDL_NOTICE,   /* normal but significant condition */
33         /* Unimportant progress messages, etc. */
34          CTDL_INFO,     /* informational */
35         /* Debugging messages */
36          CTDL_DEBUG     /* debug-level messages */
37 };
38
39 #ifdef __GNUC__
40 void lprintf (enum LogLevel loglevel, const char *format, ...) __attribute__((__format__(__printf__,2,3)));
41 void cprintf (const char *format, ...) __attribute__((__format__(__printf__,1,2)));
42 #else
43 void lprintf (enum LogLevel loglevel, const char *format, ...);
44 void cprintf (const char *format, ...);
45 #endif
46
47 extern pthread_key_t MyConKey;                  /* TSD key for MyContext() */
48
49 extern int enable_syslog;
50
51 void init_sysdep (void);
52 void begin_critical_section (int which_one);
53 void end_critical_section (int which_one);
54 int ig_tcp_server (char *ip_addr, int port_number, int queue_len,char **errormessage);
55 int ig_uds_server(char *sockpath, int queue_len, char **errormessage);
56 struct CitContext *MyContext (void);
57 struct CitContext *CreateNewContext (void);
58 void InitMyContext (struct CitContext *con);
59 void buffer_output(void);
60 void unbuffer_output(void);
61 void flush_output(void);
62 void client_write (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 void sysdep_master_cleanup (void);
67 void kill_session (int session_to_kill);
68 void *sd_context_loop (struct CitContext *con);
69 void start_daemon (int do_close_stdio);
70 void cmd_nset (char *cmdbuf);
71 int convert_login (char *NameToConvert);
72 void *worker_thread (void *arg);
73 void become_session(struct CitContext *which_con);
74 void InitializeMasterCC(void);
75 void init_master_fdset(void);
76 void create_worker(void);
77
78 extern int num_sessions;
79 extern volatile int time_to_die;
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 extern struct worker_node {
88         pthread_t tid;
89         struct worker_node *next;
90 } *worker_list;
91
92 extern int SyslogFacility(char *name);
93 extern int syslog_facility;
94
95 #ifdef DEBUG_MEMORY_LEAKS
96 #define malloc(x) tracked_malloc(x, __FILE__, __LINE__)
97 #define realloc(x,y) tracked_realloc(x, y, __FILE__, __LINE__)
98 #undef strdup
99 #define strdup(x) tracked_strdup(x, __FILE__, __LINE__)
100 #define free(x) tracked_free(x)
101 void *tracked_malloc(size_t size, char *file, int line);
102 void *tracked_realloc(void *ptr, size_t size, char *file, int line);
103 void tracked_free(void *ptr);
104 char *tracked_strdup(const char *s, char *file, int line);
105 void dump_heap(void);
106 #endif
107
108 void create_maintenance_threads(void);
109 extern pthread_t indexer_thread_tid;
110 extern pthread_t checkpoint_thread_tid;
111
112 #endif /* SYSDEP_DECLS_H */