Add some more debug messages to imap/pop3 stuff, refactor some pop3
[monky] / src / conky.h
1 /* Conky, a system monitor, based on torsmo
2  *
3  * Any original torsmo code is licensed under the BSD license
4  *
5  * All code written since the fork of torsmo is licensed under the GPL
6  *
7  * Please see COPYING for details
8  *
9  * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10  * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
11  *      (see AUTHORS)
12  * All rights reserved.
13  *
14  * This program is free software: you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation, either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  *
26  * $Id$
27  *
28  */
29
30 #ifndef _conky_h_
31 #define _conky_h_
32
33 #if defined(HAS_MCHECK_H)
34 #include <mcheck.h>
35 #endif /* HAS_MCHECK_H */
36
37 #undef EQUAL
38 #undef FALSE
39 #undef TRUE
40 #define EQUAL 0 //returnvalue of strcmp-variants when strings are equal
41 #define FALSE 0
42 #define TRUE 1
43
44 #include "config.h"
45 #include <sys/utsname.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 #include <locale.h>
50 #include <langinfo.h>
51 #include <wchar.h>
52 #include <sys/param.h>
53
54 #if !defined(__GNUC__)
55 #  define __attribute__(x) /* nothing */
56 #endif
57
58 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
59 #include "freebsd.h"
60 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
61
62 #if defined(__OpenBSD__)
63 #include "openbsd.h"
64 #endif /* __OpenBSD__ */
65
66 #ifndef HAVE_STRNDUP
67 // use our own strndup() if it's not available
68 char *strndup(const char *s, size_t n);
69 #endif /* HAVE_STRNDUP */
70
71 #ifdef AUDACIOUS
72 #include "audacious.h"
73 #endif
74
75 #ifdef XMMS2
76 #include <xmmsclient/xmmsclient.h>
77 #endif
78
79 #ifdef RSS
80 #include "rss.h"
81 #endif
82
83 #ifdef EVE
84 #include "eve.h"
85 #endif
86
87 #ifdef SMAPI
88 #include "smapi.h"
89 #endif
90
91 #ifdef NVIDIA
92 #include "nvidia.h"
93 #endif
94
95 #include "mboxscan.h"
96 #include "timed_thread.h"
97 #include "top.h"
98
99 #define DEFAULT_TEXT_BUFFER_SIZE 256
100 extern unsigned int text_buffer_size;
101
102 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
103 #define MAX_SPECIALS_DEFAULT 512
104
105 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
106 #define MAX_USER_TEXT_DEFAULT 16384
107
108 #include <sys/socket.h>
109
110 #define ERR(...) { \
111         fprintf(stderr, PACKAGE_NAME": "); \
112         fprintf(stderr, __VA_ARGS__); \
113         fprintf(stderr, "\n"); \
114 }
115
116 /* critical error */
117 #define CRIT_ERR(...) \
118         { ERR(__VA_ARGS__); exit(EXIT_FAILURE); }
119
120 /* debugging output */
121 extern int global_debug_level;
122 #define __DBG(level, ...) \
123         if (global_debug_level > level) { \
124                 fprintf(stderr, "DEBUG(%d) [" __FILE__ ":%d]: ", level, __LINE__); \
125                 fprintf(stderr, __VA_ARGS__); \
126                 fprintf(stderr, "\n"); \
127         }
128 #define DEBUG(...) __DBG(0, __VA_ARGS__)
129 #define DEBUG2(...) __DBG(1, __VA_ARGS__)
130
131 struct net_stat {
132         const char *dev;
133         int up;
134         long long last_read_recv, last_read_trans;
135         long long recv, trans;
136         double recv_speed, trans_speed;
137         struct sockaddr addr;
138         char* addrs;
139         double net_rec[15], net_trans[15];
140         // wireless extensions
141         char essid[32];
142         char bitrate[16];
143         char mode[16];
144         int link_qual;
145         int link_qual_max;
146         char ap[18];
147 };
148
149 struct dns_data {
150         int nscount;
151         char **ns_list;
152 };
153
154 struct fs_stat {
155         char path[DEFAULT_TEXT_BUFFER_SIZE];
156         char type[DEFAULT_TEXT_BUFFER_SIZE];
157         long long size;
158         long long avail;
159         long long free;
160         char set;
161 };
162
163 #include "diskio.h"
164
165 struct mail_s {                 // for imap and pop3
166         unsigned long unseen;
167         unsigned long messages;
168         unsigned long used;
169         unsigned long quota;
170         unsigned long port;
171         unsigned int retries;
172         float interval;
173         double last_update;
174         char host[128];
175         char user[128];
176         char pass[128];
177         char command[1024];
178         char folder[128];
179         timed_thread *p_timed_thread;
180         char secure;
181 };
182
183 /* struct cpu_stat {
184         unsigned int user, nice, system, idle, iowait, irq, softirq;
185         int cpu_avg_samples;
186 }; */
187
188 #ifdef MPD
189 #include "mpd.h"
190 #endif
191
192 #ifdef MOC
193 #include "moc.h"
194 #endif
195
196 #ifdef XMMS2
197 #include "xmms2.h"
198 #endif
199
200 #ifdef AUDACIOUS
201 #include "audacious.h"
202 #endif
203
204 #ifdef BMPX
205 #include "bmpx.h"
206 #endif
207
208 void update_entropy(void);
209 struct entropy_s {
210         unsigned int entropy_avail;
211         unsigned int poolsize;
212 };
213
214 struct usr_info {
215         char *names;
216         char *times;
217         char *terms;
218         int number;
219 };
220
221 struct gateway_info {
222         char *iface;
223         char *ip;
224         int count;
225 };
226
227 #ifdef X11
228 struct monitor_info {
229         int number;
230         int current;
231 };
232
233 struct x11_info {
234         struct monitor_info monitor;
235 };
236 #endif
237
238 #ifdef TCP_PORT_MONITOR
239 #include "libtcp-portmon.h"
240 #endif
241
242 enum {
243         INFO_CPU = 0,
244         INFO_MAIL = 1,
245         INFO_MEM = 2,
246         INFO_NET = 3,
247         INFO_PROCS = 4,
248         INFO_RUN_PROCS = 5,
249         INFO_UPTIME = 6,
250         INFO_BUFFERS = 7,
251         INFO_FS = 8,
252         INFO_SYSFS = 9,
253         INFO_MIXER = 10,
254         INFO_LOADAVG = 11,
255         INFO_UNAME = 12,
256         INFO_FREQ = 13,
257 #ifdef MPD
258         INFO_MPD = 14,
259 #endif
260         INFO_TOP = 15,
261         INFO_WIFI = 16,
262         INFO_DISKIO = 17,
263         INFO_I8K = 18,
264 #ifdef TCP_PORT_MONITOR
265         INFO_TCP_PORT_MONITOR = 19,
266 #endif
267 #ifdef AUDACIOUS
268         INFO_AUDACIOUS = 20,
269 #endif
270 #ifdef BMPX
271         INFO_BMPX = 21,
272 #endif
273 #ifdef XMMS2
274         INFO_XMMS2 = 22,
275 #endif
276         INFO_ENTROPY = 23,
277 #ifdef RSS
278         INFO_RSS = 24,
279 #endif
280 #ifdef SMAPI
281         INFO_SMAPI = 25,
282 #endif
283         INFO_USERS = 26,
284         INFO_GW = 27,
285 #ifdef NVIDIA
286         INFO_NVIDIA = 28,
287 #endif
288 #ifdef X11
289         INFO_X11 = 29,
290 #endif
291         INFO_DNS = 30,
292 #ifdef MOC
293   INFO_MOC = 31
294 #endif
295 };
296
297 /* get_battery_stuff() item selector */
298 enum {
299         BATTERY_STATUS,
300         BATTERY_TIME
301 };
302
303 /* if_up strictness selector */
304 enum {
305         IFUP_UP,
306         IFUP_LINK,
307         IFUP_ADDR
308 } ifup_strictness;
309
310 /* Update interval */
311 double update_interval;
312
313 volatile int g_signal_pending;
314
315 struct information {
316         unsigned int mask;
317
318         struct utsname uname_s;
319
320         char freq[10];
321
322         double uptime;
323
324         /* memory information in kilobytes */
325         unsigned long long mem, memeasyfree, memfree, memmax, swap, swapmax;
326         unsigned long long bufmem, buffers, cached;
327
328         unsigned short procs;
329         unsigned short run_procs;
330
331         float *cpu_usage;
332         /* struct cpu_stat cpu_summed; what the hell is this? */
333         unsigned int cpu_count;
334         unsigned int cpu_avg_samples;
335
336         unsigned int net_avg_samples;
337
338         float loadavg[3];
339
340         struct mail_s *mail;
341         int mail_running;
342 #ifdef MPD
343         struct mpd_s mpd;
344 #endif
345 #ifdef MOC
346   struct moc_s moc;
347 #endif
348 #ifdef XMMS2
349         struct xmms2_s xmms2;
350         int xmms2_conn_state;
351         xmms_socket_t xmms2_fd;
352         fd_set xmms2_fdset;
353         xmmsc_connection_t *xmms2_conn;
354 #endif
355 #ifdef AUDACIOUS
356         AUDACIOUS_S audacious;
357 #endif
358 #ifdef BMPX
359         struct bmpx_s bmpx;
360 #endif
361         struct usr_info users;
362         struct gateway_info gw_info;
363         struct dns_data nameserver_info;
364         struct process *cpu[10];
365         struct process *memu[10];
366         struct process *first_process;
367         unsigned long looped;
368 #ifdef TCP_PORT_MONITOR
369         tcp_port_monitor_collection_t *p_tcp_port_monitor_collection;
370 #endif
371         struct entropy_s entropy;
372         double music_player_interval;
373
374 #ifdef X11
375         struct x11_info x11;
376 #endif
377
378         short kflags;   /* kernel settings, see enum KFLAG */
379
380         unsigned int diskio_value;
381         unsigned int diskio_read_value;
382         unsigned int diskio_write_value;
383 };
384
385 enum {
386         /* set to true if kernel uses "long" format for /proc/stats */
387         KFLAG_IS_LONGSTAT = 0x01,
388         /* set to true if kernel shows # of threads for the proc value
389          * in sysinfo() call */
390         KFLAG_PROC_IS_THREADS = 0x02
391         /* bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
392         /* KFLAG_NEXT_ONE = 0x04 */
393 };
394
395 #define KFLAG_SETON(a) info.kflags |= a
396 #define KFLAG_SETOFF(a) info.kflags &= (~a)
397 #define KFLAG_FLIP(a) info.kflags ^= a
398 #define KFLAG_ISSET(a) info.kflags & a
399
400 #define TO_X 1
401 #define TO_STDOUT 2
402 int output_methods;
403
404 int top_cpu;
405 int top_mem;
406
407 int use_spacer;
408
409 enum spacer_opts { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
410
411 char *tmpstring1;
412 char *tmpstring2;
413
414 #ifdef X11
415 #include "x11.h"
416 #endif /* X11 */
417
418 int cpu_separate;
419 int short_units;
420
421 /* struct that has all info */
422 struct information info;
423
424 void signal_handler(int);
425 void reload_config(void);
426 void clean_up(void);
427
428 void update_uname(void);
429 double get_time(void);
430 FILE *open_file(const char *file, int *reported);
431 void variable_substitute(const char *s, char *dest, unsigned int n);
432 void format_seconds(char *buf, unsigned int n, long t);
433 void format_seconds_short(char *buf, unsigned int n, long t);
434 struct net_stat *get_net_stat(const char *dev);
435 void clear_net_stats(void);
436 void free_dns_data(void);
437 void update_dns_data(void);
438 void update_users(void);
439
440 #ifdef X11
441 void update_x11info(void);
442 #endif
443
444 void update_stuff(void);
445
446 int round_to_int(float f);
447
448 extern unsigned long long need_mask;
449
450 extern double current_update_time, last_update_time;
451
452 extern int no_buffers;
453
454 #if defined(__linux__)
455 #include "linux.h"
456 #endif
457
458 #include "fs.h"
459 #include "mixer.h"
460 #include "mail.h"
461
462 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
463                 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
464 int apm_getinfo(int fd, apm_info_t aip);
465 char *get_apm_adapter(void);
466 char *get_apm_battery_life(void);
467 char *get_apm_battery_time(void);
468 #endif
469
470 #ifdef HDDTEMP
471 #include "hddtemp.h"
472 #endif /* HDDTEMP */
473
474 #endif