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