Added new function calls for aide_message and lprintf.
[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 void vlprintf (enum LogLevel loglevel, const char *format, va_list arg_ptr);
54
55 extern pthread_key_t MyConKey;                  /* TSD key for MyContext() */
56
57 extern int enable_syslog;
58
59 void init_sysdep (void);
60 void begin_critical_section (int which_one);
61 void end_critical_section (int which_one);
62 int ig_tcp_server (char *ip_addr, int port_number, int queue_len,char **errormessage);
63 int ig_uds_server(char *sockpath, int queue_len, char **errormessage);
64 struct CitContext *MyContext (void);
65 struct CitContext *CreateNewContext (void);
66 void InitMyContext (struct CitContext *con);
67 void buffer_output(void);
68 void unbuffer_output(void);
69 void flush_output(void);
70 void client_write (char *buf, int nbytes);
71 int client_read_to (char *buf, int bytes, int timeout);
72 int client_read (char *buf, int bytes);
73 int client_getln (char *buf, int maxbytes);
74 void sysdep_master_cleanup (void);
75 void kill_session (int session_to_kill);
76 void *sd_context_loop (struct CitContext *con);
77 void start_daemon (int do_close_stdio);
78 void cmd_nset (char *cmdbuf);
79 int convert_login (char *NameToConvert);
80 void *worker_thread (void *arg);
81 void become_session(struct CitContext *which_con);
82 void InitializeMasterCC(void);
83 void init_master_fdset(void);
84 void create_worker(void);
85 void InitialiseSemaphores(void);
86
87 extern int num_sessions;
88 extern volatile int time_to_die;
89 extern volatile int shutdown_and_halt;
90 extern volatile int running_as_daemon;
91 extern volatile int restart_server;
92
93 extern int verbosity;
94 extern int rescan[];
95
96 extern struct worker_node {
97         pthread_t tid;
98         struct worker_node *next;
99 } *worker_list;
100
101 extern int SyslogFacility(char *name);
102 extern int syslog_facility;
103
104 #ifdef DEBUG_MEMORY_LEAKS
105 #define malloc(x) tracked_malloc(x, __FILE__, __LINE__)
106 #define realloc(x,y) tracked_realloc(x, y, __FILE__, __LINE__)
107 #undef strdup
108 #define strdup(x) tracked_strdup(x, __FILE__, __LINE__)
109 #define free(x) tracked_free(x)
110 void *tracked_malloc(size_t size, char *file, int line);
111 void *tracked_realloc(void *ptr, size_t size, char *file, int line);
112 void tracked_free(void *ptr);
113 char *tracked_strdup(const char *s, char *file, int line);
114 void dump_heap(void);
115 #endif
116
117 void create_maintenance_threads(void);
118
119 #endif /* SYSDEP_DECLS_H */